ios - 如何快速检测谷歌地图的相机位置

标签 ios google-maps swift

搜索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/

相关文章:

javascript - 如何使用他们的 API 设置 Google map 的样式

javascript - 谷歌地方信息 API : place_changed not fired

google-maps - 如何获取特定 map 的动态谷歌地图网址(我有静态 map 网址)

swift - CollecitonViewCell Dynamic With 基于Autolayout 标签Text

swift - 使用 If 语句检查 3 种可能性

ios - 为什么 block 被设计为在堆栈上分配,除非被复制?

ios - 是否可以在 Swift 中覆盖 UIButton 的操作方法?

ios - 以编程方式创建 UITableView

ios - SHLineGraphView - 设置图形原点值

ios - 启用/禁用 TableView 单元格 - iOS - Swift