我遇到地理编码器不显示每个标记的标题的问题。这是代码:
var map;
var marker = [];
function gmap_initialize() {
var ikonica = templateDir+'/images/gmap/gmap_pointer_and_shadow.png';
var map_canvas = document.getElementById('gmap');
var my_latlan = new google.maps.LatLng(45.55496, 18.69551);
var map_options = {
center: my_latlan,
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(gmap, map_options);
var geocoder = new google.maps.Geocoder();
//js_adrese below is actually an array that contains addresses
for (i=0; i<js_adrese.length; i++)
{
geocoder.geocode( {'address': js_adrese[i]}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
var x = results[0].geometry.location.lat();
var y = results[0].geometry.location.lng();
marker[i] = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
icon: ikonica,
title: js_adrese[i] // undefined in console
});
}
else
{
alert("Geocode failed. Reason: " + status);
}
});
}
};
当我设法显示标题时,它只显示 js_adrese[i] 的最后一个值,因此每个标记都有相同的标题。
重要提示:我完全是 js 和 google api 的菜鸟,所以请,如果你愿意将技术谈话降低到我的白痴水平并用蹩脚的话指出,问题是什么以及如何解决它?请