繁体   English   中英

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

[英]Calculate the distance between 2 position Google maps Api

我们要创建一个我们城市的Line Bus,我们可以使用什么样的Maps Api,我的朋友建议使用Google Map Api。 我们想知道如何以米为单位获得 2 个地方之间的距离,我找到了 distanceFrom() 方法,它生成了空气中的距离,而不是街道之间的距离。 我们有一个地址表,我们想将它与来自用户的位置进行比较以找到最近的地址。 所以我们需要找到位置和表中所有地址列表之间的较低距离。

我的代码是使用 google map deriction 服务在地图中获得 2 点或 2 个位置的距离

    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
        }
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM