Google Direction Direction服务提供错误的路线

问题描述

在具有以下坐标的地图上绘制googlemap路线。但是路线错误。问题出在哪里?

LNG                    LAT
58.5589893333333       23.6229513333333   Start
58.5589985             23.6231225         WAY POINT 1
58.5591366666667       23.6235491666667   WAY POINT 2
58.55882               23.6236481666667   WAY POINT 3
58.5476361666667       23.6209141666667   WAY POINT 4
58.5454098333333       23.616038          END

错误的路线

在Google地图网站中尝试使用相同的坐标,这给出了正确的方法

问题出在哪里?正确发送所有航路点,起点和终点。坐标来自跟踪设备。仅在某些情况下显示这样的错误路线。

var directiondisplay;
var directionsService = new google.maps.DirectionsService();
directionsdisplay = new google.maps.DirectionsRenderer();     
directionsdisplay.setMap(map);
var first = new google.maps.LatLng(23.6231225,58.5589985);
var second = new google.maps.LatLng(23.6235491666667,58.5591366666667);
var third = new google.maps.LatLng(23.6236481666667,58.55882);
var forth = new google.maps.LatLng(23.6209141666667,58.5476361666667); 
var i = 0;
var start = StartlatDir[i]+','+StartlongDir[i];
var end = EndlatDir[i] + ',' + EndlongDir[i];
var request = {
    origin: start,destination: end,waypoints: [{ location:first,stopover: false },{ location: second,{ location: third,{ location: forth,stopover: false }],optimizeWaypoints: false,travelMode: google.maps.DirectionsTravelMode.DRIVING,unitSystem: google.maps.UnitSystem.METRIC
};
directionsService.route(request,function (response,status) {
    if (status == google.maps.Directionsstatus.OK) {
        directionsdisplay.setDirections(response);
        var myRoute = response.routes[0];
        var txtDir = '';
        for (var i = 0; i < myRoute.legs[0].steps.length; i++) {
            txtDir += myRoute.legs[0].steps[i].instructions + "<br />";
        }
    }
});

解决方法

DirectionsService对出口附近(或道路的错误一侧)附近的航路点非常敏感。

Waypoint 4 (23.6209141666667,58.5476361666667)使路线离开出口。

original route

将其沿(23.620315,58.5471)的路线进一步移动即可得出预期的路线:

fiddle

map with waypoint 4 after the exit 或将其完全删除即可获得预期的路线

fiddle

map with waypoint 4 removed

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...