搜索idleAtCameraPosition 和didChangeCameraPosition 后我知道 map 移动时会调用这些方法。 我如何为 swift 编写此方法?我已将委托(delegate)设置为 CLLocationManagerDelegate 和 GMSMapViewDelegate 但仍未调用此方法。我写的方法如下:
func mapView(mapView: GMSMapView!, didChangeCameraPosition position: GMSCameraPosition!) {
print(position)
}
func mapView(mapView:GMSMapView!,idleAtCameraPosition position:GMSCameraPosition!)
{
print(position)
}
但是我的方法没有被调用。 我也想自定义信息窗口,就像这里所做的那样:Custom Info Window for Google Maps .但是找不到如何在 swift 中做同样的事情的方法。我是 swift 的新手,所以不明白这一点。
最佳答案
也许为时已晚,但您必须使用 GMSMapViewDelegate 扩展该类。例如:
class NearMeViewController: CLLocationManagerDelegate, GMSMapViewDelegate
然后,正如 Ztan 所说,您必须将您的 map 委托(delegate)给:
self.mapView.delegate = self
有了这个,didChangeCameraPosition
方法将在每次更改相机位置时做出响应。
希望对您有所帮助。
关于ios - 如何快速检测谷歌地图的相机位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28300083/