【发布时间】:2018-02-07 13:17:13
【问题描述】:
我正在使用这个脚本从地址中获取纬度经度,
var latitude="";
var longitude ="";
function codeAddress(address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == 'OK') {
latitude = results[0].geometry.location.lat();
longitude = results[0].geometry.location.lng();
// myAfterFunction();
// console.log(this.latitude);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
var center = new google.maps.LatLng(latitude,longitude );
我的问题是我无法从这个函数中获取纬度和经度值,我尝试使用另一个函数
function myAfterFunction(){
console.log(latitude);
}
所以我的问题是如何从我的函数中获取纬度和经度?谢谢
【问题讨论】:
-
你遇到了什么错误?
-
当我写 console.log(latitude);控制台.log(经度);在函数之外,它说未定义未定义
标签: javascript angular google-maps ionic-framework