IOS谷歌地图防滑适合界限

时间:2015-06-07 20:35:10

标签: 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))
            }

地图不会移动并且远离任何标记,我也没有在调试面板中看到任何错误。根据文档,这是将地图集中在一组标记上的正确方法。

1 个答案:

答案 0 :(得分:2)

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

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

bounds = bounds.includingCoordinate(position)
相关问题