本文介绍了带Waypoints的Google路线服务无法使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//显示路线( - )
if(e.keyCode == 109& $(#booking-docket)。dialog(isOpen)){
var pickup = $('#txt-pickup -lat 。-long')VAL();
var pickup pickup = pickup pickup pickup(pick.split(,)[0];
var pickupLng = pickup。pickup(,)[1];
var destination = $('#txt-destination-lat-long')。val();
var destinationLat = destination.split(,)[0];
var destinationLng = destination.split(,)[1];
var via = $('#txt-via-lat-long')。val();
var viaLat = via.split(,)[0];
var viaLng = via.split(,)[1];
var start = new google.maps.LatLng(parseFloat(pickup LP),parseFloat(pickup LBng));
var end = new google.maps.LatLng(parseFloat(destinationLat),parseFloat(destinationLng));
var waypts = new google.maps.LatLng(parseFloat(viaLat),parseFloat(viaLng));
$ b var request = {
origin:start,
destination:end,
waypoints:waypts,
optimizeWaypoints:true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request,function(response,status){
if(status == google.maps.DirectionsStatus.OK){
directionsDisplay.setDirections(response);
}
});
}
直到我加入航点,当我尝试显示路线,任何想法时,现在发生?
解决方案
您的原始示例可以更改为:
// var waypts = new google.maps.LatLng(parseFloat(viaLat),parseFloat(viaLng));
var request = {
origin:start,
destination:end,
waypoints:[{
location:new google.maps.LatLng(parseFloat (viaLat),parseFloat(viaLng)),
stopover:false
}],
optimizeWaypoints:true,
travelMode:google.maps.TravelMode.DRIVING
} ;
Here is my code for displaying waypoints with google directions:-
// Show Route (-)
if (e.keyCode == 109 && $("#booking-docket").dialog("isOpen")) {
var pickup = $('#txt-pickup-lat-long').val();
var pickupLat = pickup.split(",")[0];
var pickupLng = pickup.split(",")[1];
var destination = $('#txt-destination-lat-long').val();
var destinationLat = destination.split(",")[0];
var destinationLng = destination.split(",")[1];
var via = $('#txt-via-lat-long').val();
var viaLat = via.split(",")[0];
var viaLng = via.split(",")[1];
var start = new google.maps.LatLng(parseFloat(pickupLat), parseFloat(pickupLng));
var end = new google.maps.LatLng(parseFloat(destinationLat), parseFloat(destinationLng));
var waypts = new google.maps.LatLng(parseFloat(viaLat), parseFloat(viaLng));
var request = {
origin:start,
destination:end,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
It worked perfectly fine until I added the waypoint in, not sure why but nothing happens now when I try to show the route, any ideas?
解决方案
Your original example could be changed like:
//var waypts = new google.maps.LatLng(parseFloat(viaLat), parseFloat(viaLng));
var request = {
origin:start,
destination:end,
waypoints: [{
location: new google.maps.LatLng(parseFloat(viaLat), parseFloat(viaLng)),
stopover: false
}],
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
这篇关于带Waypoints的Google路线服务无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!