【问题标题】:Convert real distance to Google Map distance将实际距离转换为谷歌地图距离
【发布时间】:2015-03-09 17:04:47
【问题描述】:

我在 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-maps google-maps-api-3 geolocation location maps


    【解决方案1】:

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

    distance = 100 km * (5 sec / 3600 sec)
    

    【讨论】:

    • 哇,花了好几个小时。非常感谢! :)
    猜你喜欢
    • 2014-08-12
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2020-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多