【发布时间】:2014-04-01 05:57:44
【问题描述】:
我有以下代码:
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 命令也不起作用。
【问题讨论】:
-
你想用
window.get_location达到什么目的?你认为它是/做什么? -
尝试使用 'get_location' 而不是 'window.get_location'
-
使用警报('test');在条件中并尝试找出哪里出了问题
-
get_location命令也不起作用。
标签: javascript function return undefined