Possible Duplicate:
Undefined is not a function, Google Geolocation未定義在谷歌地圖API V3反向地理編碼
我試圖讓谷歌扭轉位置的地理編碼,它返回我不確定,但是,CONSOLE.LOG它顯示的地址
這是獲得功能值
function getLatLng(latlng, callback) {
var codedAddress;
geocoder.geocode({'latLng': new google.maps.LatLng(40.730885,-73.997383)}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
codedAddress = results[1].formatted_address;
console.log("codedAddress 1 = "+codedAddress);
} else {
alert("There was a problem with the map");
}
console.log("codedAddress 2 = "+codedAddress);
});
callback(codedAddress);
}
,這是我的初始化代碼
function initialize() {
var mapOptions = {
zoom: 11,
center: new google.maps.LatLng(5.386, 100.245),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var location_coords = [
<?php echo $output; ?>
];
var location_status = [
<?php echo $status; ?>
];
var location_users = [
<?php echo $users; ?>
];
var location_date = [
<?php echo $date; ?>
];
for(i=0;i<location_coords.length;i++) {
var traffic_options = {
strokeColor: '#A52A2A',
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: getColor(location_status[i]),
fillOpacity: 0.5,
map: map,
center: location_coords[i],
radius: 300
};
cityCircle = new google.maps.Circle(traffic_options);
barr[i] = new Object;
var marker = new google.maps.Marker({
position: location_coords[i],
map: map,
});
barr[i].marker = marker;
barr[i].html = "<div><span style='font-size:9px'>Reported by " + location_users[i] + " on " + location_date[i] + "</span>" +
"Traffic Location: " + getLatLng(location_coords[i], function(codedAddress) { return codedAddress; }) +
"<p>Traffic Condition: " + getCondition(location_status[i]) + "</p></div>";
barr[i].infoWindow = new google.maps.InfoWindow({
content: barr[i].html
});
barr[i].listener = makeClosure(i, barr[i].marker);
}
}
問題是這種說法
"Traffic Location: " + getLatLng(location_coords[i], function(codedAddress) { return codedAddress; })
我如何獲得的價值在這裏,而不是「未定義」內
謝謝
getLatLng()
定義在哪裏? – 2012-08-13 04:06:49低於初始化函數 – user1594367 2012-08-13 04:12:02