我有以下代码:在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