2013-12-11 198 views
0

我試圖從預定義變量addrstartnameaddrEndName添加標記到谷歌地圖。它在v2中運行得很好,但是在v3中不顯示。向谷歌地圖添加標記v3

function addMarker2Map(point,markerID,imageUrl) { 
    marker = new google.maps.Marker(point, { 
    draggable: false, 
    autoPan: false, 
    title: (markerID.toLowerCase().indexOf("start") != -1) ? 'Start Point: ' + addrStartName: 'End Point: ' + addrEndName 
    }); 
    marker.id = markerID; 
    marker.setMap(map); 
    marker.setIcon(imageUrl); 
    if (markerID.indexOf("tart") != -1) { 
    dirMarkerFrom = marker; 
    google.maps.event.addListener(marker, 'dragend', function(point) { 
     findAddrLocations(point, geocoderGetLocsFrom, geocoderNotFound); 
    }); 
    } else { 
    dirMarkerTo = marker; 
    google.maps.event.addListener(marker, 'dragend', function(point) {findAddrLocations(point, geocoderGetLocsTo, geocoderNotFound);}); 
    } 
google.maps.event.addListener(marker, 'click', function (point) { 
    if (this.id.toLowerCase().indexOf("start") != -1) { 
     this.openInfoWindow("<div style='width:200px'><img src='images/google_pointer_start.png' alt='Start Address' title='Start Address' align='middle' /> <strong>Start Address:</strong><br />" + addrStartName + "</div>"); 
     } else { 
     this.openInfoWindow("<div style='width:200px'><img src='images/google_pointer_finish.png' alt='End Address' title='End Address' align='middle'/><strong>End Address:</strong><br />" + addrEndName + "</div>"); 
    } 
}); 
} 

昨天我在marker.setIcon(imageUrl);附近發現錯誤,但今天工作正常。

調用這個函數也是一個例子可以在這裏看到

google.maps.event.removeListener(mapClick); 
    if (point != undefined){ 
    addMarker2Map(point,markerID,imageUrl) 
        } 

預先感謝您的任何幫助

回答

1

google.maps.Marker的構造函數不正確。

只需要一個參數,一個MarkerOptions object

marker = new google.maps.Marker(point,{draggable:false, autoPan:false, title:  (markerID.toLowerCase().indexOf("start") != -1)?'Start Point: '+addrStartName:'End Point:  '+addrEndName}); 

應該是:

marker = new google.maps.Marker({position: point, draggable:false, autoPan:false, title:  (markerID.toLowerCase().indexOf("start") != -1)?'Start Point: '+addrStartName:'End Point:  '+addrEndName}); 
+0

謝謝你,我已經實施了,但沒有運氣我怕。我添加了一個例子,當我將這個函數調用到我的原始文章中的代碼。 – Corinne

+0

然後還有更多的問題(運氣不應該涉及)。您需要爲我們提供足夠的代碼來複制問題(或者展示問題的jsfiddle或鏈接) – geocodezip