问题描述
||
问候,
到目前为止,我主要使用的是Google Maps v2。我现在正在迈向v3,但是遇到了一个我无法找到解决方案的问题。
在V2中,当使用方向时,我可以在地图上添加一条没有实际道路的点,而Maps 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)
您对API的v3版本有过类似的经历吗?任何想法为什么会发生这种情况?
更新:这是一个链接,显示了运行中的代码和问题:
http://jsfiddle.net/spairus/gNpZ2/
解决方法
从图形看来,您的lng / lat可能顺序错误。如此处建议的那样,您可能需要确保以正确的顺序使用经度和纬度。