0
陣列我有地理編碼器外的陣列,但是當我想用內部地理編碼數組的數組的值是不確定的無法訪問內部地址解析器
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
}
}
}
確保數組的前面沒有「var」宣言。在JavaScript'var ab'中表示'ab'是一個作用域局部變量。 – Fallen
向我們展示**生成的** JavaScript。 –