google maps api 3 route finder(路线的POI距离)

时间:2012-05-21 15:13:21

标签: google-maps-api-3

我有以下代码,可以成功绘制两点之间的路线。但是,我希望搜索记录集,以查看哪条地理参考位于此路线的范围内。例如。距主干道50码

function plot_route() {

         var rendererOptions = { map: map };
    directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);

    var org = new google.maps.LatLng ( $("#start_lat").html(), $("#start_long").html() );
    var dest = new google.maps.LatLng ( $("#finish_lat").html(), $("#finish_long").html() );

        if ($("#via_lat").html() != "") {
       var point1 = new google.maps.LatLng($("#via_lat").html(), $("#via_long").html());
        }
        else
        {
         point1 = dest;
        }

    var wps = [{ location: point1 }];

    if (($("#start_lat").html() != "") && ($("#finish_lat").html() != "")) {
    var request = {
            origin: org,
            destination: dest,
            waypoints: wps,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
            };

    directionsService = new google.maps.DirectionsService();
    directionsService.route(request, function(response, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                    directionsDisplay.setDirections(response);
                }
                else
                    alert ('failed to get directions');
            });
    }
}

我尝试分解响应,但它显示计算不返回组成路径的值数组。

有人曾经征服过这个吗?

修改

深入挖掘,似乎响应确实包含路线点阵列。对于社区中寻求帮助的人而不是人们用-1按钮做贡献我附上以下内容

function plot_route() {

         var rendererOptions = { map: map };
    directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);

    var org = new google.maps.LatLng ( $("#start_lat").html(), $("#start_long").html() );
    var dest = new google.maps.LatLng ( $("#finish_lat").html(), $("#finish_long").html() );

        if ($("#via_lat").html() != "") {
       var point1 = new google.maps.LatLng($("#via_lat").html(), $("#via_long").html());
        }
        else
        {
         point1 = dest;
        }

    var wps = [{ location: point1 }];

    if (($("#start_lat").html() != "") && ($("#finish_lat").html() != "")) {
    var request = {
            origin: org,
            destination: dest,
            waypoints: wps,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
            };

    directionsService = new google.maps.DirectionsService();
    directionsService.route(request, function(response, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                                   var myroute = response.routes[0];
                                   if(myroute)
                                   {
                                       $.each(myroute, function(key, value) {
                                       if (key == "overview_path") {
                                          alert(value); //the array of points for the route
                                       }
                                     });
                                    }
                    directionsDisplay.setDirections(response);
                }
                else
                    alert ('failed to get directions');
            });
    }
}

0 个答案:

没有答案