Google地图视图颜色错误

时间:2018-03-01 14:44:22

标签: swift google-maps

如果按下按钮,我想更改标记位置。我尝试过如下。但它看起来像这样。一些颜色将如何改变为这样。 我怎样才能解决这个问题?谢谢!

enter image description here

@objc func changeMarker() {
        let next = CLLocationCoordinate2DMake(40.730610, -73.935242)
        mapView.camera = GMSCameraPosition.camera(withLatitude: next.latitude, longitude: next.longitude, zoom: 13)
        let marker = GMSMarker(position: next)
        marker.title = "over here"
        marker.map = mapView
    }

1 个答案:

答案 0 :(得分:1)

添加此标记并尝试此

    func addMarker() {
        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2D(latitude: CLLocationDegrees(yourCoordinateLatitude), longitude: CLLocationDegrees(yourCoordinateLongitude))
        marker.map = mapView
    }

现在您可以缩放到标记

func zoomToCoordinate(coordinate: CLLocationCoordinate2D, zoom: Float) {
        CATransaction.begin()
        CATransaction.setValue(1, forKey: kCATransactionAnimationDuration)
        let camera = GMSCameraPosition.camera(withLatitude: coordinate.latitude, longitude: coordinate.longitude, zoom: zoom)
        self.animate(to: camera)
        CATransaction.commit()
    }

我会这样称呼它

mapView.clear() // to clear your mapView
mapView.addMarker()
mapView.zoomToCoordinate(coordinate: yourCoordinate, zoom: 15)

始终检查您的功能是否被调用以及协调是否正确。

此代码适用于我的项目。如果它对您的项目不起作用,请分享更多代码。