IOS 谷歌地图防滑边界

标签 ios google-maps google-maps-sdk-ios

我在 UIViewController 的 viewDidLoad 方法中有以下代码。它位于从远程服务器获取位置列表后调用的回调函数中。

            var bounds = GMSCoordinateBounds()

            for place in self.placeCollection.places {

                var position = CLLocationCoordinate2DMake(place.latitude, place.longitude)
                bounds.includingCoordinate(position)
                var marker = GMSMarker(position: position)
                marker.title = place.title;
                marker.map = self.mapView;
            }

            if self.placeCollection.places.count > 0 {
                self.mapView.moveCamera(GMSCameraUpdate.fitBounds(bounds))
            }

map 没有移动,也没有靠近任何标记,我也没有在调试面板中看到任何错误。根据文档,这是将 map 聚焦在一组标记上的正确方法。

最佳答案

bounds.includingCoordinate 不会更新 bounds,而是返回包含新点的新 GMSCoordinateBounds

所以,你需要这样的东西:

bounds = bounds.includingCoordinate(position)

关于IOS 谷歌地图防滑边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30698212/

相关文章:

ios - 尝试从 DynamoDB (Swift) 读取时出现 DynamoDBObjectModel 错误

ios - Sprite Kit 背景滚动垂直

javascript - Leaflet.label 未显示在标记上

ios - 如何知道 View Controller 是否将呈现为弹出窗口或模式?

iOS - Admob 内存泄漏

javascript - 使用谷歌地图删除路线

google-maps - 检查坐标是否包含在Google map 的圆内?

ios - 将 GMSMarker 添加到 map 时,应用程序仅在 iPhone 5 上崩溃 : EXC_BAD_ACCESS

ios - 如何在 Swift 中实现 GMUClusterRenderer

ios - View 左上角的 GMSMarker 图标 (iOS)