Swift 谷歌地图缩放

Swift 谷歌地图缩放,swift,google-maps,dictionary,colors,zooming,Swift,Google Maps,Dictionary,Colors,Zooming,我正在尝试从lat-long缩放特定pin上的谷歌地图。它工作正常,但我想在swift中放大pin时更改pin图像。我这样做过,但在同一lat-long上放置了2个图像 func zoom(lat: Double, long : Double){ CATransaction.begin() CATransaction.setValue(1, forKey: kCATransactionAnimationDuration) // It will a

我正在尝试从lat-long缩放特定pin上的谷歌地图。它工作正常,但我想在swift中放大pin时更改pin图像。我这样做过,但在同一lat-long上放置了2个图像

func zoom(lat: Double, long : Double){
        CATransaction.begin()
        CATransaction.setValue(1, forKey: kCATransactionAnimationDuration)

        // It will animate your camera to the specified lat and long
        let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: long, zoom: 15)
        self.mapView!.animate(to: camera)
        let position = CLLocationCoordinate2D(latitude: lat,longitude: long)
        let marker = GMSMarker()
        marker.map = self.mapView
        marker.icon = UIImage.init(named: "pin-1")

         CATransaction.commit()
    }

您可以设置一个检测缩放级别变化的函数,然后设置一个将改变标记图标值的条件

下面是我的代码的样子:

import UIKit
import GoogleMaps

class ViewController: UIViewController, GMSMapViewDelegate {
 let marker = GMSMarker()

    override func viewDidLoad() {

    }

   override func loadView() {
    // Create a GMSCameraPosition that tells the map to display the
        // coordinate -33.86,151.20 at zoom level 6.
        let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
        let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        self.view = mapView

    mapView.delegate = self

        // Creates a marker in the coordinate of the map.

        marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
        marker.title = "Sydney"
        marker.snippet = "Australia"
        marker.map = mapView
       marker.icon = UIImage(named: "pin_orange")
    }

//This detect the changes in the cameraposition
    func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
          let zoom = mapView.camera.zoom
          print("map zoom is ",String(zoom))

        //put a condition here to change the icon of your marker
        if zoom > 6 {
            marker.icon = UIImage(named: "icon1")
        }else{
            marker.icon = UIImage(named: "icon2")
        }
    }
}
希望这有帮助