【发布时间】:2018-02-06 13:48:35
【问题描述】:
我正在使用 google API 和地理编码器,我需要在地理编码后将位置信息(经度和纬度)保存在一些变量中。 在这段代码中,我可以提醒返回值,但我不知道如何将这些值保存在变量中。
function codeAddress() {
var address = "Streamwood, IL, USA";
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var loc=[];
loc[0]=results[0].geometry.location.lat();
loc[1]=results[0].geometry.location.lng();
display(loc);
} else {
alert("Error: " + status);
}
});
}
function display(loc){
alert(loc[0]);
}
【问题讨论】:
标签: javascript google-maps google-maps-api-3 google-geocoder google-geocoding-api