duanfu7004 2014-07-08 15:19
浏览 312
已采纳

计算2个位置谷歌地图Api之间的距离

We want to create a Line Bus of our City , what kind of Maps Api , we can use , My friend prposed to use Google Map Api. We want to know howto get the distance beetwen 2 places in meter , i found the method distanceFrom() and it generate the distance in the air and not beetwen street . We have a Table of Adress , and we want to compare it with a position who came from the user to find the Closest adress. so we need to find the lower distance beetwen the position and all the list of adress in the table. Thank you

  • 写回答

1条回答 默认 最新

  • duanhuo3392 2014-07-08 17:36
    关注

    My code is get distance of 2 point or 2 location in map with google map deriction service

        var PolylineOption = {
            strokeColor : "blue",
            strokeOpacity : 0.5,
            strokeWeight : 5
        };
        var request = {
            origin : polyline[0].start, // điểm đầu
            waypoints : polyline[1].waypoint,
            destination : polyline[2].end, // Điểm cuối
            optimizeWaypoints : true,
            travelMode : google.maps.TravelMode.DRIVING
        };
        rendererOptions = {
                    draggable : true,
                    suppressMarkers : true,
                    polylineOptions : this.PolylineOption
        };
        var Service = new google.maps.DirectionsService();
        var Display = new google.maps.DirectionsRenderer(rendererOptions);
        Display.setMap(map);
        Service.route(this.request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                distance += response.routes[0].legs[0].distance.value;
                // distance of 2 location
            }
        });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler