我有一个代码:
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var map = new google.maps.Map(document.getElementById('map'), {
zoom:6,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
directionsDisplay.setMap(map);
var request = {
origin: '<?= $_GET['from']; ?>',
destination: '<?= $_GET['to']; ?>',
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
route=Math.round(parseFloat(response.routes[0].legs[0].distance.value)*0.002);
}
});
当我在两个输入中输入新的起点和目的地时,我需要让谷歌地图刷新路线,我正在考虑:
function renewMap() {
loc=$('input[name=location]').val();
des=$('input[name=destination]').val();
var request = {
origin: loc,
destination: des,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
route=Math.round(parseFloat(response.routes[0].legs[0].distance.value)*0.002);
}
});
}
但显然这行不通。