【发布时间】:2015-03-09 17:04:47
【问题描述】:
我在 Google 地图 (Android) 上有一个 marker,我想将标记移动到给定 bearing 和 distance 的新位置。
//lat, lng in degrees. Bearing in degrees. Distance in Km
private LatLng newPostion(Double lat,Double lng,Double bearing,Double distance) {
Double R = 6371; // Earth Radius in Km
Double lat2 = Math.asin(Math.sin(Math.PI / 180 * lat) * Math.cos(distance / R) + Math.cos(Math.PI / 180 * lat) * Math.sin(distance / R) * Math.cos(Math.PI / 180 * bearing));
Double lon2 = Math.PI / 180 * lng + Math.atan2(Math.sin( Math.PI / 180 * bearing) * Math.sin(distance / R) * Math.cos( Math.PI / 180 * lat ), Math.cos(distance / R) - Math.sin( Math.PI / 180 * lat) * Math.sin(lat2));
Double newLat = 180 / Math.PI * lat2;
Double newLng = 180 / Math.PI * lon2;
LatLng newLatLng = new LatLng(newLat, newLng);
return newLatLng;
}
LatLng newPos = newPostion(myMark.getPosition().latitude,myMark.getPosition().longitude, 90.0,3000.0);
距离是计算速度*时间。
distance = speed * time
假设标记代表一辆汽车,汽车以 100 公里/小时的速度行驶,我需要每 5 秒更新一次标记。
distance = 100 * (5/60)
但问题是在 Google 地图上显示 distance,因为 Google 地图是按比例缩放的。使用上面计算的距离来移动标记将使标记移动得更远。
谁能帮我将实际距离转换为谷歌地图距离?
【问题讨论】:
标签: google-maps google-maps-api-3 geolocation location maps