引用腾讯地图js:<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&libraries=geometry"></script>
线路距离:
var map,
directionsService = new qq.maps.DrivingService({
complete: function (response) {
var start = response.detail.start,
end = response.detail.end;
directions_routes = response.detail.routes;
var distance = directions_routes[0].distance;//总距离
}
}),directions_routes;
function sosoDistance(start_lat, start_lng, end_lat, end_lng) {
//LEAST_TIME 最少时间
//LEAST_DISTANCE 最短距离
//AVOID_HIGHWAYS 避开高速
//REAL_TRAFFIC 实时路况
//PREDICT_TRAFFIC 预测路况
directionsService.setPolicy(qq.maps.DrivingPolicy["LEAST_DISTANCE"]);
directionsService.search(new qq.maps.LatLng(start_lat, start_lng),
new qq.maps.LatLng(end_lat, end_lng));
}
----------------------------我是漂亮的分割线-------------------------------------------------
直线距离:
var start = new qq.maps.LatLng(start_lat, start_lng), end = new qq.maps.LatLng(end_lat, end_lng);
var total = Math.round(qq.maps.geometry.spherical.computeDistanceBetween(start, end) * 10) / 10;