我开始为自己的Google地图单独列出我的标记,但很快意识到这是效率低下的 。我试图创建一个数组来把标记放到我的地图上,但它没有显示任何东西,你能看到我出错的地方吗?与Google Maps API的标记阵列拼搏
function initialize() {
var latlng = new google.maps.LatLng(52.474, -1.868);
var myOptions = {
zoom: 11,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var image = 'i/hotel-map-pin.png';
var hotels = [
['ibis Birmingham Airport', 52.452656, -1.730548, 4],
['ETAP Birmingham Airport', 52.452527, -1.731644, 3],
['ibis Birmingham City Centre', 52.475162, -1.897208, 2]
];
for (var i = 0; i < hotels.length; i++) {
var marker = new google.maps.Marker({
position: hotels[1],
map: map,
icon: image,
title: hotels[0],
zIndex: hotels[2]
});
}
}
谢谢。
当然 - 我是一个涂料!谢谢。 – DarrylGodden 2011-04-28 13:45:32
@Gogster没问题。这是一个容易犯的错误。 – RedBlueThing 2011-04-28 23:57:13
为什么不使用foreach(酒店作为酒店)让您的生活更轻松? – mydoglixu 2014-11-20 03:35:15