私はコードをもっている:
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);
}
});
何か考えている2つの入力に新しい出発地と目的地を入力すると、Googleマップにルートを更新させる必要があります。
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);
}
});
}
しかし、明らかにこれは機能しません。