如何使坐标数组与谷歌地图sdk适合iOS的界限? 我需要为4个可见标记缩放地图。如何使坐标数组与谷歌地图sdk for iOS的界限?
回答
这是我对这个问题的解决方案。通过多个坐标构建GMSCoordinateBounds对象。
- (void)focusMapToShowAllMarkers
{
CLLocationCoordinate2D myLocation = ((GMSMarker *)_markers.firstObject).position;
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
for (GMSMarker *marker in _markers)
bounds = [bounds includingCoordinate:marker.position];
[_mapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:15.0f]];
}
更新答案:由于GMSMapView中标记财产已被弃用,您应该保存所有标记在自己的阵列。
更新迅速的3回答:
func focusMapToShowAllMarkers() {
let firstLocation = (markers.first as GMSMarker).position
var bounds = GMSCoordinateBoundsWithCoordinate(firstLocation, coordinate: firstLocation)
for marker in markers {
bounds = bounds.includingCoordinate(marker.position)
}
let update = GMSCameraUpdate.fitBounds(bounds, withPadding: CGFloat(15))
self.mapView.animate(cameraUpdate: update)
}
工作正常。虽然标记属性现在已被弃用。我使用了数组中的标记位置。 – 2013-12-15 08:30:03
谢谢,我用这个很棒的解决方案:)但是@ManishAhuja说,我用我自己存储的GMSMarker数组来构建边界。 – 2014-08-19 19:07:06
谢谢@ManishAhuja和AubadaTaijo。 Iv'e更新了答案。 – Lirik 2014-08-20 20:29:50
暂时,谷歌终于实现了GMSCoordinateBounds, ,您可以使用它与GMSCameraUpdate。
详情请查看官方reference。
雨燕3.0版本Lirik的回答:
func focusMapToShowAllMarkers() {
let myLocation: CLLocationCoordinate2D = self.markers.first!.position
var bounds: GMSCoordinateBounds = GMSCoordinateBounds(coordinate: myLocation, coordinate: myLocation)
for marker in self.markers {
bounds = bounds.includingCoordinate(marker.position)
self.mapView.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 15.0))
}
}
下面是我自己的方式:
func focusMapToShowMarkers(markers: [GMSMarker]) {
guard let currentUserLocation = self.locationManager.location?.coordinate else {
return
}
var bounds: GMSCoordinateBounds = GMSCoordinateBounds(coordinate: currentUserLocation,
coordinate: currentUserLocation)
_ = markers.map {
bounds = bounds.includingCoordinate($0.position)
self.mapView.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 15.0))
}
}
你可以叫我功能如上所示:
- 1. 如何禁用Google地图sdk for iOS中的谷歌链接?
- 2. 如何实施iOS谷歌地图SDK
- 3. Android谷歌地图坐标
- 4. 谷歌地图坐标圈
- 5. Android谷歌地图坐标
- 6. Android:谷歌地图坐标
- 7. 使用谷歌地图使用坐标
- 8. 谷歌地图SDK iOS版:重新定位谷歌标志
- 9. 谷歌地图操作Lat/Lng坐标
- 10. 如何设置区域与谷歌地图SDK的iOS?
- 11. 遍历数组数组并传递坐标到谷歌地图
- 12. 如何使用谷歌地图sdk获取CGPoint的iOS位置?
- 13. 谷歌地图的Android更改界限
- 14. 谷歌街景使用谷歌地图sdk为ios
- 15. 如何适应在地图上的所有可见对象/界限(谷歌地图iOS版SDK 1.4)
- 16. 设置谷歌地图边界与角谷歌地图
- 17. 如何确保谷歌地图iOS SDK不使用私有API?
- 18. 谷歌地图的隐藏坐标
- 19. 谷歌地图上的GPS坐标
- 20. 谷歌地图iOS SDK崩溃 - GMSBackgroundAppException
- 21. 谷歌地理编码 - 坐标地址与坐标
- 22. iOS版谷歌地图SDK术语
- 23. 谷歌地图GMSMaker ICONVIEW - iOS版SDK
- 24. 计算谷歌地图瓦片边界坐标
- 25. iPhone SDK:从谷歌地图获取GPS坐标
- 26. 如何获取我的谷歌地图窗口的边界框坐标
- 27. 带谷歌地图SDK的iOS可拖拽标记器
- 28. 谷歌地图SDK徽标选项
- 29. 如何查找标记谷歌地图的坐标
- 30. 谷歌地图API定位角坐标
我在这里回答你类似的问题:http://stackoverflow.com/questions/15040409/how-to-setregion-with-google-maps-sdk-for-ios – 2013-02-28 12:02:15