问题描述
在具有以下坐标的地图上绘制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 />";
}
}
});