我有以下代码成功绘制了两点之间的路线。但是,我希望搜索记录集以查看哪些地理参考位于此路线的范围内。例如,距离主要路线 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');
});
}
}