我想获得驾驶距离两条经度纬度点之间的轨道,地理编码器或任何其他有效的方式。 是否有?获取两个经度纬度点之间的驾驶距离
0
A
回答
2
Google Maps API v3 documentation指定来源或目的地(或航点)可以是地址或google.maps.LatLng。要获取两个经度/纬度点之间的驾驶距离,请将它们作为google.maps.LatLng对象传递给request。
相关的问题:total distance and time for all waypoints in google maps v3
代码段(基于关the example in the documentation):
function initMap() {
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 7,
center: {
lat: 41.85,
lng: -87.65
}
});
directionsDisplay.setMap(map);
// New York, NY, USA (40.7127837, -74.0059413)
var start = new google.maps.LatLng(40.7127837, -74.0059413);
//Baltimore, MD, USA (39.2903848, -76.6121893)
var end = new google.maps.LatLng(39.2903848, -76.6121893);
calculateAndDisplayRoute(start, end, directionsService, directionsDisplay);
}
function calculateAndDisplayRoute(start, end, directionsService, directionsDisplay) {
directionsService.route({
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
}, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
var totaldistance = 0;
var route = response.routes[0];
// display total distance information.
for (var i = 0; i < route.legs.length; i++) {
totaldistance = totaldistance + route.legs[i].distance.value;
}
document.getElementById('distance').innerHTML += "<p>total distance is " + (totaldistance/1000).toFixed(2) + " km</p>";
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
google.maps.event.addDomListener(window, "load", initMap);
html,
body,
#map {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="distance"></div>
<div id="map"></div>
+0
精心制作的回应请帮助 –
1
var R = 6371;
var dLat = toRad(lat2-lat1);
var dLon = toRad(lon2-lon1);
var dLat1 = toRad(lat1);
var dLat2 = toRad(lat2);
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(dLat1) * Math.cos(dLat1) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
alert(d);
function toRad(Value) {
/** Converts numeric degrees to radians */
return Value * Math.PI/180;
+0
这只是一个直线距离不是驾驶距离 –
0
如果你不想依赖(精心制作的)Google API或绑定API限制,我只是发现了另一个选项:OpenStreetMap的osrm-project。
在我的情况下,我需要检索近20万个房屋的最近开车距离到某个特定的兴趣点。
相关问题
- 1. 两个经纬度之间的距离
- 2. 测量两个纬度/经度点之间的距离
- 3. 计算两个纬度 - 经度点之间的距离? - 钛
- 4. 获取两点之间的驾驶距离
- 5. 如何找到纬度/经度/纬度点之间的距离?
- 6. 如何计算经度和纬度两点之间的距离?
- 7. 计算两点之间的距离(经度,纬度)
- 8. 经典ASP中两个纬度/长点之间的距离
- 9. 如何获得两点之间的驾驶距离?
- 10. 如何根据纬度和经度获得两个地点之间的距离?
- 11. 两个经度和纬度之间的距离
- 12. 在ArcGIS中获取站点之间的驾驶距离
- 13. 如何快速估算两个(纬度,经度)点之间的距离?
- 14. 分别计算两个纬度和两个经度之间的距离
- 15. 使用R和Google Map API获取两点之间的驾驶距离
- 16. 找到2个经纬度点之间的距离(单位:米)
- 17. 纬度经度对之间的距离精度
- 18. 纬度和经度两点之间的表面距离源代码javascript
- 19. 使用纬度经度和海拔(海拔)计算两点之间的距离
- 20. 使用rethinkdb 2个经纬度点之间计算距离
- 21. 获取经纬度和纬度的距离
- 22. 获取从纬度/经度点沿折线距离
- 23. 在iOS中获取驾驶距离
- 24. 如何使用angulajs计算两个纬度和经度之间的距离?
- 25. 用于计算两个纬度和经度之间距离的MySQL函数
- 26. 计算两个纬度和经度地理坐标之间的距离
- 27. 纬度/经度数学问题(两个坐标之间的距离)
- 28. 如何检查两个纬度和经度coorindates之间的距离?
- 29. 找到两个纬度和经度之间的距离在SQL查询
- 30. 获取基于距离和度数的经度纬度组合
你有做过任何研究吗? – geocodezip
[Google Maps API v3文档](https://developers.google.com/maps/documentation/javascript/reference#DirectionsService)指定来源或目的地(或航点)可以是地址,也可以是[ google.maps.LatLng](https://developers.google.com/maps/documentation/javascript/reference#LatLng)。要获取两个经度/纬度点之间的驾驶距离,请将它们作为google.maps.LatLng对象在[请求](https://developers.google.com/maps/documentation/javascript/reference#DirectionsRequest)中传递。 – geocodezip
非常感谢你 – user1666543