你好我试图通过调用循环外的函数将id的两个位置保存到一个数组中。问题是它给了我一个错误,说 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