【问题标题】:Calculate the distance between 2 position Google maps Api计算2个位置谷歌地图Api之间的距离
【发布时间】:2014-08-29 09:54:55
【问题描述】:

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

【问题讨论】:

  • 听起来您正在寻找DirectionsMatrix(也是Web Service。但是有一些限制,它是否有效取决于您需要多少个位置之间的距离。

标签: javascript php mysql google-maps google-maps-api-3


【解决方案1】:

我的代码是使用谷歌地图识别服务获取地图中 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
        }
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2011-09-21
    相关资源
    最近更新 更多