IOS Google 地图防滑配合范围
IOS Google Maps skid fit bounds
我在 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))
}
地图没有移动,也没有靠近任何标记,我在调试面板中也没有看到任何错误。根据文档,这是将地图聚焦在一组标记上的正确方法。
bounds.includingCoordinate
不会更新 bounds
,而是 returns 包含新点的新 GMSCoordinateBounds
。
所以,你需要这样的东西:
bounds = bounds.includingCoordinate(position)
我在 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))
}
地图没有移动,也没有靠近任何标记,我在调试面板中也没有看到任何错误。根据文档,这是将地图聚焦在一组标记上的正确方法。
bounds.includingCoordinate
不会更新 bounds
,而是 returns 包含新点的新 GMSCoordinateBounds
。
所以,你需要这样的东西:
bounds = bounds.includingCoordinate(position)