【问题标题】:Get/Calculate zoom level from lat/long delta从纬度/经度增量获取/计算缩放级别
【发布时间】:2016-06-22 03:59:53
【问题描述】:

有没有什么方法可以根据 iOS 版 Google Maps SDK 的纬度/经度增量值计算 Google Maps 缩放级别?

或者也许通过 Objective C 来计算?

谢谢

【问题讨论】:

  • 我猜您正在尝试更改缩放,所以这两个点都适合地图?在这种情况下,您可以使用 + (GMSCameraUpdate *) fitBounds:(GMSCoordinateBounds *) bounds;或 + (GMSCameraUpdate *) fitBounds:(GMSCoordinateBounds *) bounds withPadding:(CGFloat)padding ;
  • 是的,我正在尝试计算缩放,获取纬度/经度增量值,然后转换为缩放级别。不太明白你的建议,能详细点吗?

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


【解决方案1】:

也许这就是你要找的。​​p>

来自 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]];

【讨论】:

  • 如果我有 3-4 个坐标,我怎么能找到东北和西南。我确实尝试了包括坐标和包括路径。但结果不同
【解决方案2】:

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

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.......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-28
    • 1970-01-01
    • 2020-03-19
    • 2012-01-10
    • 1970-01-01
    • 2011-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多