【问题标题】:Scale custom marker icon according to zoom level根据缩放级别缩放自定义标记图标
【发布时间】:2015-11-01 02:15:18
【问题描述】:

我正在尝试根据缩放级别缩放自定义标记图标。当你放大得很近时,我的图标应该很大,但很明显,当你放大很远时它会变大,所以它应该自动缩小。

我的最新方法是这样的:

var myscale = CGFloat()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    mapView.delegate = self

    mapView.myLocationEnabled = true

    if let mylocation = mapView.myLocation {
        print(mylocation)
        // use for camera position later on
    }
    else {
        // do sth else
    }

    let camera = GMSCameraPosition.cameraWithLatitude(47.962433, longitude: 12.526859, zoom: 17)
    mapView.camera = camera

    let userImage = UIImage(named: "test_profile_pic.png")!
    let userIcon = UIImage(data: UIImagePNGRepresentation(userImage)!, scale: myscale)

    let marker = GMSMarker()
    marker.icon = userIcon
    marker.position = CLLocationCoordinate2DMake(45.962433, 13.526859)
    marker.title = "testMarker"
    marker.snippet = "testSnippet"
    marker.map = mapView

    segmentedControl.layer.cornerRadius = 5
    segmentedControl.layer.masksToBounds = true

}
func mapView(mapView: GMSMapView!, didChangeCameraPosition position: GMSCameraPosition!) {
    if (mapView.camera.zoom <= 16) {
        myscale = 4.0
    }
    // as soon is this works, some fine tuning in scaling
}

使用这种方法,图像不会重新缩放到我在didChangeCameraPosition 中设置的值,因为它已经加载了比例 1.0。我真的不明白如何更新我的 UIImage 的比例。任何帮助表示赞赏。

【问题讨论】:

    标签: ios swift google-maps-sdk-ios


    【解决方案1】:

    你必须先清除地图,然后重新添加标记!

    【讨论】:

      猜你喜欢
      • 2018-10-07
      • 2017-10-14
      • 1970-01-01
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-19
      相关资源
      最近更新 更多