我在Google Map中绘制了两个点。我想根据道路计算两点之间的距离。任何解决方案或工作代码?如何计算谷歌地图中两个坐标之间的距离?
0
A
回答
1
您可以使用以下方法计算两个经纬度点之间的距离。
public static float distFrom (float lat1, float lng1, float lat2, float lng2)
{
double earthRadius = 3958.75;
double dLat = Math.toRadians(lat2-lat1);
double dLng = Math.toRadians(lng2-lng1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;
int meterConversion = 1609;
return new Float(dist * meterConversion).floatValue();
}
0
你可以做到这一点通过API的:有一个ComputeDistanceBetween功能中的“几何”库,“球形”的命名空间。参考:https://developers.google.com/maps/documentation/javascript/geometry
它这样使用:
var distance = google.maps.geometry.spherical.computeDistanceBetween(latLong, latLong);
2
只要使用Android的内置Location
类,用于获取两个位置之间的距离。
你也可以试试这个,
Location locationA = new Location("location A");
locationA.setLatitude(locationA.getLatitudeE6()/1E6);
locationA.setLongitude(locationA.getLongitudeE6()/1E6);
Location locationB = new Location("location B");
locationB.setLatitude(locationB.getLatitudeE6()/1E6);
locationB.setLongitude(locationB.getLongitudeE6()/1E6);
double distance = locationA.distanceTo(locationB);
相关问题
- 1. 如何计算谷歌地图中两点之间的距离?
- 2. 无法计算谷歌地图中两点之间的距离
- 3. 我们如何计算两个坐标之间的距离。 ArangoDB
- 4. 使用iphone中的谷歌地图计算两个位置之间的距离
- 5. 计算坐标之间的距离
- 6. 机器人,两地之间的计算距离,谷歌距离矩阵
- 7. 计算两个纬度坐标之间的距离/方位
- 8. 计算两个GPRS坐标之间的距离
- 9. 计算两个x/y坐标之间的距离?
- 10. 游戏 - 计算两个坐标之间的距离
- 11. 谷歌地图API总距离计算
- 12. 谷歌地图距离计算
- 13. 使用谷歌地图计算距离
- 14. /谷歌地图来计算距离
- 15. 蟒蛇谷歌地球坐标距离计算
- 16. 两个坐标之间的距离
- 17. 谷歌应用程序脚本地图API两点之间的距离计算
- 18. 谷歌地图API - V3两个多边形之间的距离
- 19. 如何计算ArrayList中两个标记之间的距离?
- 20. 计算两组坐标之间的距离(NSStrings)
- 21. 计算两个纬度和经度地理坐标之间的距离
- 22. 来计算地球上两个坐标之间的行驶距离在php
- 23. 谷歌地图 - 如何获得米之间的两点之间的距离?
- 24. 如何在谷歌地图上获取六十进制数,并且计算两个两性之间的距离?
- 25. 如何计算两个地址之间的距离
- 26. 如何计算两个地理点之间的距离
- 27. 如何计算2之间的距离坐标
- 28. pgf/tikz:如何计算x坐标之间的一半距离?
- 29. 谷歌地图上两个坐标之间的绘制线
- 30. 谷歌地图:指定路线上两点之间的距离