你好,我試圖通過調用一個函數在循環外部將這兩個位置的id保存到一個數組中。問題是它給了我一個錯誤,說loc不是一個函數。有誰知道問題在哪裏?爲什麼它說loc不是函數
var geocoder;
var map, x, y;
var loc = [];
geocoder = new google.maps.Geocoder();
// var address = document.getElementById("address").value;
// var user='33936357';
$.getJSON("http://api.twitter.com/1/users/lookup.json?user_id=33936357,606020001&callback=?", function (data) {
$.each(data, function (i, item) {
var screen_name = item.screen_name;
var img = item.profile_image_url;
var location = item.location;
geocoder.geocode({
address: location
}, function (response, status) {
if (status == google.maps.GeocoderStatus.OK) {
var x = response[0].geometry.location.lat(),
y = response[0].geometry.location.lng();
loc(x, y);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
}); //GEOCODER.GEOCODE
});
function loc(x, y) {
loc.push({
latitude: x,
longitude: y
});
}
console.log(loc); //$.EACH
}); //.GETJSON
} //CODEADDRESS
您似乎已通過修改代碼來刪除問題而使問題失效。請恢復不正確的代碼,以便答案有意義(然後接受幫助您的答案)。 – 2012-08-09 10:48:38