我有一張使用DirectionsRender繪製的路線,但我找不到如何用我自己的替換通用Google標記。如何在谷歌地圖v3 API中更改開始和結束標記圖像
我知道並在正常的Google地圖情況下使用它,但發現使用指示標記開始和結束時很難做到這一點。
感謝您的任何意見,指針或溫和的嘲諷,如果這是一個愚蠢的問題:d
邁克爾
我有一張使用DirectionsRender繪製的路線,但我找不到如何用我自己的替換通用Google標記。如何在谷歌地圖v3 API中更改開始和結束標記圖像
我知道並在正常的Google地圖情況下使用它,但發現使用指示標記開始和結束時很難做到這一點。
感謝您的任何意見,指針或溫和的嘲諷,如果這是一個愚蠢的問題:d
邁克爾
這就是你需要如何處理它
聲明你的所有的圖像圖標,如圖下面
var movingIcon = new google.maps.MarkerImage('/img/icon_moving.jpg');
var startIcon = new google.maps.MarkerImage('/img/icon_start.png');
然後在創建標記,使用IC上選項來特定圖像設置爲標記
marker = new google.maps.Marker({
position: point,
map: map,
icon: movingIcon
});
的DirectionRender
接受一個選項稱爲markerOptions
。從API文檔引用:
DirectionsRenderer呈現的所有標記都將使用這些選項。
所以,如果你想設置標記使用MarkerImage(如philar已指示)。
您的其他選擇是通過suppressMarkers: true
到DirectionRender
的選項,然後只需使用自己的標記。
首先,你需要添加這對您的DirectionsRenderer
directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers: true});
//to hide the default icons
再經過選擇等等
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
//you set your custom image
var image = new google.maps.MarkerImage('images/image.png',
new google.maps.Size(129, 42),
new google.maps.Point(0,0),
new google.maps.Point(18, 42)
);
//you set your icon for each of the direction points Origin
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(19.432651,-99.133201),
map: map,
icon: image
});
//you set your icon for each of the direction points Destination,
var marker2 = new google.maps.Marker({
position: new google.maps.LatLng(45.508648,-73.55399),
map: map,
icon: image
});
,你也可以爲始發地和目的地添加不同的圖標。只需使用var圖像, 它適合我!
他問的是如何更改標記的方向呈現這只是回答如何更改標記圖標。 – 2012-02-09 13:51:50