2016-05-19 122 views
-1

這裏是我的網站目前的樣子:https://gyazo.com/ee7851e912a1b7fb4118f80ad0f35a53更改多個谷歌地圖標記的位置上點擊

它顯示在左邊,第一個驅動器中投遞路線的送貨司機。我希望能夠點擊其他任何驅動程序並顯示其交付路線。下面是HTML我現在有每個驅動程序:

<li onclick="changeDelivery(54.35024,-6.26928,54.38252,-6.30836);"> 
      <!-- driver info --> 
     </li> 

這裏是我的javascript:

function initMap() { 
var pickup = {lat: 54.34633, lng: -6.27175}; 
var dropoff = {lat: 54.34786, lng: -6.25146}; 

var map = new google.maps.Map(document.getElementById('map'), { 
    center: pickup, 
    scrollwheel: true, 
    zoom: 7, 
    disableDefaultUI: true, 
}); 

var directionsDisplay = new google.maps.DirectionsRenderer({ 
    map: map, 
    suppressMarkers: true, 
    polylineOptions: { 
     strokeColor: "#24A4EA", 
     strokeWeight: 5 
    } 
}); 

// Set destination, origin and travel mode. 
var request = { 
    destination: dropoff, 
    origin: pickup, 
    travelMode: google.maps.TravelMode.DRIVING 
}; 

// Pass the directions request to the directions service. 
var directionsService = new google.maps.DirectionsService(); 
    directionsService.route(request, function(response, status) { 
     if (status == google.maps.DirectionsStatus.OK) { 
      // Display the route on the map. 
      directionsDisplay.setDirections(response); 
     } 
}); 

var pickupIcon = new google.maps.MarkerImage('img/pickup-icon.png'); 
var dropoffIcon = new google.maps.MarkerImage('img/dropoff-icon.png'); 

var pickupMarker = new google.maps.Marker({ 
    position: pickup, 
    map: map, 
    icon: pickupIcon 
}); 

var dropoffMarker = new google.maps.Marker({ 
    position: dropoff, 
    map: map, 
    icon: dropoffIcon 
}); 
} 

google.maps.event.addDomListener(window, 'load', initMap); 

function changeDelivery(pickupLat,pickupLng,dropoffLat,dropoffLng) { 
    var pickup = {lat: pickupLat, lng: pickupLng}; 
    var dropoff = {lat: dropoffLat, lng: dropoffLng}; 
} 

目前,我想獲得通過點擊列表項調用函數changeDelivery和期望其參數將地圖上的拾取和放下標記更新爲新的座標。任何原因,這是行不通的,或者我應該如何去做這件事?

感謝, 傑米

回答

相關問題