我正在构建一个播放解决方案,根据通过gps设备发送的存储路点,在地图上设置动画和移动车辆标记。
Gps设备向相反方向发送一些偏移路径点,这会影响地图上绘制的路线 (计算出的路线是错误的)在我用来做的代码之下:
function setRoutes() {
var directionsDisplay = new Array();
var rendererOptions = {
map: map,
suppressMarkers: true,
preserveViewport: true
}
directionsService = new google.maps.DirectionsService();
var travelMode = google.maps.DirectionsTravelMode.DRIVING;
var request = {
origin: start,
destination: end,
waypoints: wayPoints,
travelMode: travelMode
};
directionsService.route(request,
function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var bounds = new google.maps.LatLngBounds();
var route = response.routes[0];
startLocation = new Object();
endLocation = new Object();
// For each route, display summary information.
var path = response.routes[0].overview_path;
var legs = response.routes[0].legs;
disp = new google.maps.DirectionsRenderer(rendererOptions);
disp.setMap(null);
disp.setDirections(response);
//Markers
for (i = 0; i < legs.length; i++) {
if (i == 0) {
startLocation.latlng = legs[i].start_location;
startLocation.address = legs[i].start_address;
// marker = google.maps.Marker({map:map,position: startLocation.latlng});
//marker[routeNum] = createMarker(legs[i].start_location, msg.DeviceId, legs[i].start_address, "green");
}
endLocation.latlng = legs[i].end_location;
endLocation.address = legs[i].end_address;
var steps = legs[i].steps;
for (j = 0; j < steps.length; j++) {
var nextSegment = steps[j].path;
var nextSegment = steps[j].path;
for (k = 0; k < nextSegment.length; k++) {
polyline.getPath().push(nextSegment[k]);
}
}
}
}
startAnimation();
});
}
我该怎么办?