【发布时间】:2011-08-05 23:39:24
【问题描述】:
你好,
到目前为止,我大部分时间都在使用谷歌地图 v2。我现在正在使用 v3,但遇到了一个我无法找到解决方案的问题。
在 V2 中,使用路线时,我可以在地图上添加一个没有实际道路的点,地图 api 会自动找出可能存在道路的最近端点并显示到该点的路线。不过,V3 似乎并非如此。在分配的情况下,路线是错误的,因为我没有将我的点放在实际的道路上,并且服务失败(?)找到最近的。这是显示我的意思的屏幕截图:
我对两张地图使用完全相同的坐标。 V3 上的红色大头针显示了这些坐标实际指向的位置,但您可以看到方向是错误的。仅当我使用正好在道路上的坐标时,它们才会正确显示(此处未显示)。我在 V2 和 V3 上使用完全相同的坐标,但只有 V2 显示正确的方向。
这是我用来获取指令的代码示例:
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
//Works fine, so I ommit the code
}
function calcRoute(endpointCoords) // endpointCoords holds coordinates for end point
{
var startpoint = '<?=$startPoint[latitude];?>, <?=$startPoint[longitude];?>';
var endpoint = endpointCoords;
var request = {
origin:startpoint,
destination:endpoint,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status){
if (status == google.maps.DirectionsStatus.OK)
{
directionsDisplay.setDirections(response);
}
});
}
文档并没有进一步帮助我 (http://code.google.com/apis/maps/documentation/javascript/services.html#Directions)
v3 版本的 api 你有过类似的经历吗?任何想法为什么会发生这种情况?
更新:这是一个显示代码和实际问题的链接: http://jsfiddle.net/spairus/gNpZ2/
【问题讨论】:
标签: google-maps google-maps-api-3