我有以下代碼:在javascript函數返回值未定義
JS負載:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
js函數:
<script type="text/javascript">
var get_location;
function get_google_latlng() {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': 'iran'}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
window.get_location = results[0].geometry.location.lat();
} else {
window.get_location = status;
}
});
return window.get_location;
}
var lat = get_google_latlng();
alert(lat);
</script>
回報功能是undefined
window.get_location
命令也不起作用。
[如何從AJAX調用返回響應?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – elclanrs
你想用'window.get_location'達到什麼目的?你認爲這是/是什麼? –
嘗試使用「get_location」而不是「window.get_location」 – Selva