SDK在特定缩放级别显示标记吗

SDK在特定缩放级别显示标记吗

本文介绍了iOS Swift Google Maps SDK在特定缩放级别显示标记吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google地图上有标记,一旦用户缩放到地图上的特定缩放级别,我想为其设置动画以使其不被隐藏,然后当用户缩小时,标记再次被隐藏. /p>

在Snapchat的SnapMap中可以看到类似的功能.

这种行为如何实现?

在google map的didChangeposition委托方法中,我可以保留当前的缩放级别,但是从那里如何为标记添加动画?我没有看到一种方法来访问当前显示的标记数组.

有什么想法吗?

解决方案

您可以使用googlemaps的"didchange"委托例如:

func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
    if mapView.camera.zoom >= 16 {
         // ADD YOUR MARKERS HERE
    } else {
        mapView.clear()
    }
}

如果您想将动画添加进去,这对我有用

func addMarker() {
        self.markerArray.removeAll()

        for data in yourDataArray {
            let iconView = UIImageView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
            iconView.image = UIImage(named: "YOUR_IMAGE")
            iconView.contentMode = .scaleAspectFit

            // Creates a marker in the center of the map.
            let marker = GMSMarker()
            marker.position = CLLocationCoordinate2D(latitude: data.lat, longitude: data.lng)
            marker.iconView = iconView
            marker.tracksViewChanges = true
            marker.map = mapView

            self.markerArray.append(marker)

            UIView.animate(withDuration: 0.7,
                       animations: {
                  marker.iconView?.frame = CGRect(x: 0, y: 0, width: 29.0, height: 34.0)
            }, completion: nil)
        }
}

func removeMarker() {
        for marker in self.markerArray {
            UIView.animate(withDuration: 0.3,
                           animations: {
                   marker.iconView?.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
            }, completion: nil)
        }

        self.mapView.clear()
        self.markerArray.removeAll()
}

I have markers on my google map and I want to animate them to become un-hidden once the user zooms to a specific zoom level on the map, and then when the user zooms back out, the marker is hidden again.

A similar functionality can be seen in Snapchat's SnapMap.

How is this behavior attainable?

In google map's didChangeposition delegate method I can get a hold of the current zoom level, but from there how could I animate in and out the markers? I'm not seeing a way to access the array of markers currently being shown.

Any ideas?

解决方案

You can use a "didchange" delegate from googlemapsas an example :

func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
    if mapView.camera.zoom >= 16 {
         // ADD YOUR MARKERS HERE
    } else {
        mapView.clear()
    }
}

If you want to add animated in out, this works for me

func addMarker() {
        self.markerArray.removeAll()

        for data in yourDataArray {
            let iconView = UIImageView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
            iconView.image = UIImage(named: "YOUR_IMAGE")
            iconView.contentMode = .scaleAspectFit

            // Creates a marker in the center of the map.
            let marker = GMSMarker()
            marker.position = CLLocationCoordinate2D(latitude: data.lat, longitude: data.lng)
            marker.iconView = iconView
            marker.tracksViewChanges = true
            marker.map = mapView

            self.markerArray.append(marker)

            UIView.animate(withDuration: 0.7,
                       animations: {
                  marker.iconView?.frame = CGRect(x: 0, y: 0, width: 29.0, height: 34.0)
            }, completion: nil)
        }
}

func removeMarker() {
        for marker in self.markerArray {
            UIView.animate(withDuration: 0.3,
                           animations: {
                   marker.iconView?.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
            }, completion: nil)
        }

        self.mapView.clear()
        self.markerArray.removeAll()
}

这篇关于iOS Swift Google Maps SDK在特定缩放级别显示标记吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 07:57