How do I handle Google map markers with info windows if more than 100
Example http://econym.org.uk/gmap/example_maptypecontrols2.htm
Let's say I have 100 markers with info windows. How do I handle it?
Should I list this code for 100 times on my javascript?
var point = new GLatLng(43.91892,-78.89231);
va开发者_开发百科r 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);
Let me know
You could create an array with JSON, which can be generated on the server and loaded asynchronously.
{ 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" }
]
}
Then create a function to make you markers:
function displayMarker(item){
var point = new GLatLng(item.lat, item.lon);
var marker = createMarker(point, item.html);
map.addOverlay(marker);
}
Then loop over your array of items, calling that function every time.
精彩评论