【问题标题】:How can I get the center of a polygon using Google Maps?如何使用谷歌地图获得多边形的中心?
【发布时间】:2020-04-07 19:09:20
【问题描述】:

在我的项目中,我有一个 CLLocationCoordinate2D 数组,我需要找到它的中心点。在Android google maps sdk中,有一个计算中心的漂亮函数...

LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(listOfBounds);
LatLngBounds bounds = builder.build();

centerLatLng = bounds.getCenter();

是否有与此等效的函数可以计算ios sdk中包含的中心点,还是我必须自己编写函数?

【问题讨论】:

标签: ios swift google-maps


【解决方案1】:

如果您的边界是 CGRect,则使用 rect.midxrect.midy 很容易获得中心。如果您的 LatLngBounds 是 GMSCoordinateBounds,则通过

获取中点
let centerLatitude = bounds.northEast.latitude + bounds.southWest.latitude
let centerLongitude = bounds.southWest.longitude + bounds.northEast.longitude

我不知道 iOS SDK 中的中心功能。

【讨论】:

    猜你喜欢
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多