从纬度/经度增量获取/计算缩放级别

时间:2013-10-29 21:20:13

标签: objective-c google-maps-sdk-ios

有什么方法可以从Google Maps SDK for iOS中的纬度/经度增量值计算谷歌地图缩放级别?

或者可以通过Objective C计算它?

感谢

2 个答案:

答案 0 :(得分:1)

也许这就是你要找的东西。

来自GMSCoordinateBounds.h:

 /**
 * Inits the northEast and southWest bounds corresponding
 * to the rectangular region defined by the two corners.
 *
 * It is ambiguous whether the longitude of the box
 * extends from |coord1| to |coord2| or vice-versa;
 * the box is constructed as the smaller of the two variants, eliminating the
 * ambiguity.
 */
 - (id)initWithCoordinate:(CLLocationCoordinate2D)coord1
          coordinate:(CLLocationCoordinate2D)coord2;

可用于将相机设置为适合具有适当缩放级别的边界。

CLLocationCoordinate2D coord1 = CLLocationCoordinate2DMake(-45.43563456, -23.32543646);
CLLocationCoordinate2D coord2 = CLLocationCoordinate2DMake(-21.32145323, -12.32455435);
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:coord1 coordinate:coord2];

[mapView moveCamera: [GMSCameraUpdate fitBounds:bounds]];

答案 1 :(得分:0)

如果有人正在搜索swift,我也需要它来自动完成,你可以设置界限(例如德国西南部弗赖堡和斯图加特附近):

let coord1 : CLLocationCoordinate2D = CLLocationCoordinate2DMake(48.10009, 8.206787);
        let coord2 :  CLLocationCoordinate2D = CLLocationCoordinate2DMake(48.10009, 8.206787);
        let bounds = GMSCoordinateBounds(coordinate: (coord1), coordinate: (coord2))
        placesClient?.autocompleteQuery(autoQuery, bounds: bounds, filter: filter, callback: { (results, error: NSError?) -> Void in and so on.......