簡體   English   中英

如果超過100個,我該如何使用信息窗口處理Google地圖標記

[英]How do I handle Google map markers with info windows if more than 100

范例http://econym.org.uk/gmap/example_maptypecontrols2.htm

假設我有100個帶有信息窗口的標記。 我該如何處理?

我應該在JavaScript上將此代碼列出100次嗎?

  var point = new GLatLng(43.91892,-78.89231);
  var marker = createMarker(point,'Some stuff to display in the<br>Second Info Window')
  map.addOverlay(marker);

  var point = new GLatLng(43.82589,-79.10040);
  var marker = createMarker(point,'Some stuff to display in the<br>Third Info Window')
  map.addOverlay(marker);

讓我知道

您可以使用JSON創建一個數組,該數組可以在服務器上生成並異步加載。

{ markers : [
    { lat : 43.91892, lon : -78.89231, html : "Stuff to display" },
    { lat : 43.91892, lon : -78.89231, html : "Stuff to display" },
    { lat : 43.91892, lon : -78.89231, html : "Stuff to display" },
    { lat : 43.91892, lon : -78.89231, html : "Stuff to display" }
  ]
}

然后創建一個使您成為標記的函數:

function displayMarker(item){
    var point = new GLatLng(item.lat, item.lon);
    var marker = createMarker(point, item.html);
    map.addOverlay(marker);
}

然后遍歷您的項目數組,每次都調用該函數。

暫無
暫無

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

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