我在地理编码器外部有一个数组,但是当我想在地理编码器内部使用该数组时,该数组的值未定义
var titles = new Array(<?php echo implode(",",$titles); ?>);
var length = postCode.length;
for (var i = 0; i < length; i++)
{
geocoder.geocode({'address': postCode[i]}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
lat2 = results[0].geometry.location.lat();
lng2 = results[0].geometry.location.lng();
var Latlng = new google.maps.LatLng(lat2, lng2);
var marker = new google.maps.Marker({
position: Latlng,
map: map,
title: titles[i],
icon: icon});
// alert(titles[i]) - all undefined
}
}
}