将实际距离转换为Google Map距离

时间:2015-01-11 23:38:02

标签: google-maps google-maps-api-3 geolocation location maps

我在Google地图(Android)上有一个marker,我希望将标记移动到给定bearingdistance的新位置。

//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地图距离吗?

1 个答案:

答案 0 :(得分:1)

在距离计算中,您将秒与分钟(5秒,60分钟)混合。它应该是:

distance = 100 km * (5 sec / 3600 sec)
相关问题