如何使用iOS版Google Maps SDK拟合坐标数组的边界? [英] How to fit bounds for coordinate array with google maps sdk for iOS?
本文介绍了如何使用iOS版Google Maps SDK拟合坐标数组的边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用iOS版Google Maps sdk拟合坐标数组的边界? 我需要缩放地图以显示4个可见标记.
How to fit bounds for coordinate array with google maps sdk for iOS? I need to zoom map for 4 visible markers.
推荐答案
这是我针对此问题的解决方案.通过多个坐标构建GMSCoordinateBounds
对象.
Here's my solution for this problem. Building a GMSCoordinateBounds
object by multiple coordinates.
- (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
markers 属性,因此应将所有标记保存在自己的数组中.
Updated answer: Since GMSMapView
markers property is deprecated, you should save all markers in your own array.
更新了迅速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)
}
这篇关于如何使用iOS版Google Maps SDK拟合坐标数组的边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文