谷歌地图api信息框插件和多个标记 [英] google maps api infobox plugin and multiple markers
问题描述
如何在使用信息框插件时创建具有不同内容的多个标记 http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/infobox-basic.html
How can I create multiple markers with different content when using infobox plugin http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/infobox-basic.html
我正在创建 var 标记 1、var 标记 2 等,但我认为这不是一个很好的方法,而且我在所有信息窗口中都有相同的内容...
I was creating var marker1, var marker2 etc but I think this is not really nice method and I have the same content in all infowindows...
推荐答案
您只需要使用某种工厂生成标记,例如:
You just need to generate the markers with a factory of some sort, e.g:
function initMarkers(map, markerData) {
var newMarkers = []
// Here's where all the really verbose code goes. Loop through `markerData` to
// create each marker. See the full code in the js fiddle
return newMarkers;
}
function initialize_google_map() {
//Here the call to initMarkers() is made with the necessary data for each marker.
//All markers are then returned as an array into the markers variable, Usually you'd
//get the data from server or something, here it's just shown inline.
var markers = initMarkers(map, [
{ latLng: new google.maps.LatLng(49.47216, -123.76307), address: "Address 1", state: "State 1" },
{ latLng: new google.maps.LatLng(49.47420, -123.75703), address: "Address 2", state: "State 2" },
{ latLng: new google.maps.LatLng(49.47530, -123.78040), address: "Address 3", state: "State 3" }
]);
}
在这个 jsfiddle 中查看包含 HTML 和其他内容的完整示例 .
Check out the full example with HTML and whatnot in this jsfiddle.
这篇关于谷歌地图api信息框插件和多个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!