我有一个小问题,我有以下代码,除了标记的标题外,显然一切正常。它总是显示数组列表的最后一个标题。有人知道为什么会出现这个错误吗?
代码:
$(document).ready(function() {
var options = {
zoom: 7,
center: new google.maps.LatLng(42.19708, 2.19075),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true
};
var geocoder = new google.maps.Geocoder();
var map = new google.maps.Map(document.getElementById('map_canvas'), options);
var companys = [
['Giga S.L', 'Plaça de Catalunya, Barcelona'],
['Torre M', 'Plaça d\'Espanya, Barcelona']
];
var address;
var title;
for (var i = 0; i < companys.length; i++) {
address = companys[i][1];
title = companys[i][0];
geocoder.geocode({'address': address}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
new google.maps.Marker({
map: map,
animation: google.maps.Animation.DROP,
position: results[0].geometry.location,
title: title // ERROR: ALWAYS THE SAME TITLE
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
});
先感谢您。
此致。