gpt4 book ai didi

google-maps - google maps api infobox插件和多个标记

转载 作者:行者123 更新时间:2023-12-04 05:14:33 27 4
gpt4 key购买 nike

使用信息框插件http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/infobox-basic.html时如何创建具有不同内容的多个标记

我正在创建var marker1,var marker2等,但是我认为这并不是一个很好的方法,并且在所有信息窗口中我都拥有相同的内容...

最佳答案

您只需要使用某种工厂来生成标记,例如:

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" }
]);
}

查看完整的HTML示例,而不是 in this jsfiddle

关于google-maps - google maps api infobox插件和多个标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7308875/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com