草庐IT

Swift Google Maps Center on Marker Click

coder 2023-07-17 原文

我正在尝试将 Google map 置于标记的中心并在用户点击标记时缩放。我可以使用点击委托(delegate)在 Android 中执行此操作,但我找不到在 Swift 中执行此操作的方法。

有没有人有任何提示或建议来解决这个问题?

最佳答案

你必须符合 GMSMapViewDelegate 协议(protocol),然后你有下面的功能:

func mapView(mapView: GMSMapView, didTapMarker marker: GMSMarker) -> Bool {

    //you can handle zooming and camera update here 

}

您可以通过为多个位置创建边界来更新相机,例如:(您也可以为边界提供填充)

let bounds = GMSCoordinateBounds(coordinate: self.userLocation!.coordinate, coordinate: marker.position)
self.mapView.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(bounds, withPadding: 120.0))

你也可以用一个缩放级别的位置更新相机位置,如:

self.mapView?.camera = GMSCameraPosition.cameraWithTarget(marker.position, zoom: 9.0)

关于Swift Google Maps Center on Marker Click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31845977/

有关Swift Google Maps Center on Marker Click的更多相关文章

随机推荐