【问题标题】:How to calculate "bounds" around a point with a distance for update camera. Google Maps IOS API如何计算更新相机距离的点周围的“边界”。谷歌地图IOS API
【发布时间】:2017-10-30 13:09:27
【问题描述】:
对于我的应用程序,我想计算中心点周围区域的“边界”。该区域应由左右以及顶部和底部的距离来定义。
例如:
中心位置:4.0000 - 44.0000
+/- 500m(右-左)
+/- 700m(顶部 - 底部)
我的问题:如何计算应用函数的边界:
GMSCameraPosition * camera = [mapView cameraForBounds: bounds insets: UIEdgeInsetsZero];
谢谢。
【问题讨论】:
标签:
ios
google-maps
camera
maps
bounds
【解决方案1】:
我找到了解决方案:
公式:
φ2 = asin( sin φ1 ⋅ cos δ + cos φ1 ⋅ sin δ ⋅ cos θ )
λ2 = λ1 + atan2( sin θ ⋅ sin δ ⋅ cos φ1, cos δ − sin φ1 ⋅ sin φ2 )
其中φ是纬度,λ是经度,θ是方位角(从北顺时针方向),δ是角距离d/R; d是经过的距离,R是地球的半径
JavaScript:(所有角度以弧度表示)
var φ2 = Math.asin( Math.sin(φ1)*Math.cos(d/R) +
Math.cos(φ1)*Math.sin(d/R)*Math.cos(brng) );
var λ2 = λ1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(φ1),
Math.cos(d/R)-Math.sin(φ1)*Math.sin(φ2));
可以使用 (lon+540)%360-180 将经度归一化为 -180…+180
来自网站:http://www.movable-type.co.uk/scripts/latlong.html