在最基本的情況下,圖標可以簡單地表示一個要代替默認的 Google Maps 圖釘圖標的圖像。要指定這樣的圖
標,請將標記的 icon
屬性設置為某個圖像的 URL。Google Maps API 將自動調整圖標大小。
簡單圖標代碼如下:
marker = new google.maps.Marker({
position: new google.maps.LatLng(30.54024807, 104.06966686),
title:'Hello World!',
draggable: true,
icon:'2.png',
animation: google.maps.Animation.DROP,
map:map
});
您也許想要指定復雜的形狀來表示可點擊的區域,并指定這些圖標相對于其他疊層的顯示方式(即它們的“疊放
順序”)。以這種方式指定的圖標應該將其 icon
屬性設置為一個 Icon
類型的對象。
Icon
對象定義了一個圖像。該對象還定義了圖標的 size
(大小)、圖標的 origin
(原點,例如當您想要
的圖像是一個較大圖像的一部分時),以及 anchor
(錨點),錨點是圖標熱點的所在之處(基于原點)。
var image = {
url: '2.png',
//標注的大小32*32像素
size: new google.maps.Size(32, 32),
//標注的原點是0,0
origin: new google.maps.Point(0, 0),
// 錨點在底邊上
anchor: new google.maps.Point(0, 32)
};
marker = new google.maps.Marker({
position: new google.maps.LatLng(30.54024807, 104.06966686),
title:'Hello World!',
draggable: true,
icon:image,
zIndex:100,
animation: google.maps.Animation.DROP,
map:map
});