如何通过API V3获取Google地图上显示的路线的航点列表? [英] How to get the list of waypoints of a route displayed on the Google maps, through their API V3?
问题描述
谷歌地图API的 GDirections 类帮助我显示两个提供的坐标之间的路线。
现在我想要一个列表 ALL 该路线上的坐标。
有关如何获得此信息的提示?
刚刚发现 http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsRoute
其 overview_path 属性给出了路线的所有航点的列表。
是 DirectionsRoute 这个问题的正确类还是我缺少一点?
编辑 - 2 >
借助此链接 mkram0 下面显示,我修改了代码如下:
Map IS显示。
Route IS正在显示。
我正在考虑在路线上的前四个坐标上放置标记。这些标记不会显示。任何帮助?请。
directionsService.route(request,
function(result,status)
{
(if status == google.maps.DirectionsStatus.OK)
{
directionsDisplay.setDirections(result);
for(var route in result.routes)
{
for(var leg in route.legs)
{
for(var step in leg.steps)
{
for(var latlng in step.path )
{
pointsArray.push(latlng);
}
}
}
}
var point1 = new google.maps.Marker({
position:pointsArray [0],
draggable:true,
map:map,
flat:true
});
var point2 =新增google.maps.Marker({
位置:pointsArray [1],
可拖曳:true,
map:map,
flat:true
});
var point3 =新的google.maps.Marker({
位置:pointsArray [2],
可拖曳:true,
map:map,
flat:true
});
var point4 =新的google.maps.Marker({
位置:pointsArray [3],
可拖曳:true,
map:map,
flat:true
});
}
});
解决这个问题:)
overview_path 是显示坐标的正确方法:
仅用于检查是否真的显示了某些内容,我在结果的前四个坐标上显示了标记。
directionsService.route(request,
function(result,status)
{
alert(status);
if(状态== google.maps.DirectionsStatus.OK)
{
directionsDisplay.setDirections(result);
var pointsArray = [];
pointsArray = result.routes [0] .overview_path;
var point1 =新的google.maps.Marker({
position:pointsArray [0],
draggable:true,
map:map,
flat:true
});
var point2 =新增google.maps.Marker({
位置:pointsArray [1],
可拖曳:true,
map:map,
flat:true
});
var point3 =新的google.maps.Marker({
位置:pointsArray [2],
可拖曳:true,
map:map,
flat:true
});
var point4 =新的google.maps.Marker({
位置:pointsArray [3],
可拖曳:true,
map:map,
flat:true
});
The GDirections class of Google maps API helped me in "displaying" the route between two supplied coordinates.
Now I want a list of ALL the coordinates on that route.
Any hints on how to get this?
EDIT Just now discovered http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsRoute
Its overview_path property gives the list of ALL the waypoints of the route. Is DirectionsRoutethe right class for this problem Or I am missing some point?
EDIT - 2
With the help of this link shown by mkram0 below, I have modified the code as follows:
The Map IS getting displayed. The Route IS getting displayed.
I was thinking of placing markers on the first four coordinates on the route. Those markers don't get displayed. Any helps? Please.
directionsService.route (request,
function (result, status)
{
if (status == google.maps.DirectionsStatus.OK)
{
directionsDisplay.setDirections (result);
for (var route in result.routes)
{
for (var leg in route.legs)
{
for (var step in leg.steps)
{
for (var latlng in step.path)
{
pointsArray.push(latlng);
}
}
}
}
var point1 = new google.maps.Marker ({
position:pointsArray[0],
draggable:true,
map:map,
flat:true
});
var point2 = new google.maps.Marker ({
position:pointsArray[1],
draggable:true,
map:map,
flat:true
});
var point3 = new google.maps.Marker ({
position:pointsArray[2],
draggable:true,
map:map,
flat:true
});
var point4 = new google.maps.Marker ({
position:pointsArray[3],
draggable:true,
map:map,
flat:true
});
}
});
Solved this myself :) The overview_path was the correct method w.r.t displaying the coordinates: Just for checking if this really shows something, I have displayed markers on the resulting first four coordinates.
directionsService.route (request,
function (result, status)
{
alert(status);
if (status == google.maps.DirectionsStatus.OK)
{
directionsDisplay.setDirections (result);
var pointsArray = [];
pointsArray = result.routes[0].overview_path;
var point1 = new google.maps.Marker ({
position:pointsArray[0],
draggable:true,
map:map,
flat:true
});
var point2 = new google.maps.Marker ({
position:pointsArray[1],
draggable:true,
map:map,
flat:true
});
var point3 = new google.maps.Marker ({
position:pointsArray[2],
draggable:true,
map:map,
flat:true
});
var point4 = new google.maps.Marker ({
position:pointsArray[3],
draggable:true,
map:map,
flat:true
});
这篇关于如何通过API V3获取Google地图上显示的路线的航点列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!