我遇到过这样的情况,我应该确定给定坐标列表的中位数并设置 GoogleMap 的相机缩放级别(以便所有坐标在 map 加载时显示在单个 View 中,用户不需要缩放 map )。
我按照以下方法确定给定坐标的中位数。
Convert lat/lon to Cartesian coordinates for each location.
X = cos(lat) * cos(lon)
Y = cos(lat) * sin(lon)
Z = sin(lat)
Compute average x, y and z coordinates.
x = (x1 + x2 + ... + xn) / n
y = (y1 + y2 + ... + yn) / n
z = (z1 + z2 + ... + zn) / n
Convert average x, y, z coordinate to latitude and longitude.
Lon = atan2(y, x)
Hyp = sqrt(x * x + y * y)
Lat = atan2(z, hyp)
引用:Calculate the center point of multiple latitude/longitude coordinate pairs
现在我想设置 Google map 的相机缩放值,以便在单个 View 中覆盖所有坐标。
例如:
如果确定坐标列表出现在加利福尼亚和佛罗里达,则加载 Google map 时应显示整个美国。
如果确定坐标列表存在于加利福尼亚和德克萨斯之间,则在设置 GoogleMap 的缩放值时应仅显示美国 map 的那部分。
我正在 Andriod 应用程序和 iOS 中实现它。
让我知道我们如何才能做到这一点。
最佳答案
iOS SDK 具有类似的功能。您可以创建一个 GMSCoordinateBounds
然后用 GMSCameraUpdate:fitBounds
创建一个新相机并调用animateWithCameraUpdate:
在 mapView 对象上,传入新相机。
关于android - 如何计算给定坐标列表的 GEO 中位数并提出 Google map View 的缩放级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17050439/