簡體   English   中英

谷歌地圖更改標記圖標

[英]google maps change Icon of marker

我試圖更改標記圖標,並使用以下代碼放置我自己的圖標,但插入該圖標后,什么也沒出現。 有什么建議嗎?

var marker = new google.maps.Marker({
    position: location,
    map: map,
    icon: 'c:\green.jpg'
});

您必須將圖像(green.jpg)放在程序可訪問的文件夾中。 例如,將其放在WAR文件夾中。 如果只有HTML,PHP,...頁面,則將圖像放在同一文件夾中

圖標值應為URI,因此在這種情況下,您可能需要向其傳遞文件URI。

file:///C:/green.jpg

顯然,如果要在Web上使用此功能,則需要使用Web服務器提供的內容的URL,而不是計算機上的圖像文件。

嘗試使用setIcon()函數。 類似於marker.setIcon(“ iconfile”)

有關此功能的更多信息,請訪問: https : //developers.google.com/maps/documentation/javascript/reference#Marker

搜索:“ setIcon(icon:string | MarkerImage)”

您可以嘗試使用文件的相對路徑:

var marker = new google.maps.Marker({
    position: location,
    map: map,
    icon: 'img/markers/brown_MarkerE.png'
});

我希望這有幫助。

您必須指定要使用的協議,在您的情況下為file:// 文件傳輸協議

var marker = new google.maps.Marker({
    position: location,
    map: map,
    icon: 'http://c:/green.jpg'
});

注意:您必須將圖像存儲在Web服務器上,以使每個人都可以訪問。 這樣,只有具有C分區圖像“ grren.jpg”的用戶才能看到該圖標。

here is the full document for that with example :
https://developers.google.com/maps/tutorials/customizing/custom-markers

you can also use this code:

var marker = new google.maps.Marker({
    position: location,
    map: map,
    icon: 'your_img.png'
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM