腾讯地图 获取各种情况的总距离

引用腾讯地图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;

转载于:https://www.cnblogs.com/Liq-Blog/p/3773846.html

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页