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


Calculate the distance between 2 position Google maps Api

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

我的代码是获取距离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
        }
    });