如何从角度2的纬度,经度中获取完整的地址 [英] how to get full address from latitude,longitude in angular 2
本文介绍了如何从角度2的纬度,经度中获取完整的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用有角度的2-google-maps.
如何在带有typescript的angular2谷歌地图中从纬度,经度获取类似于国家和地名的地址?
I am using angular 2-google-maps.
how to get Address like country and pin from latitude,longitude in angular2 google maps with typescript ?
推荐答案
这对我有用
getCurrentLocation() {
this.mapsAPILoader.load().then(() => {
let geocoder = new google.maps.Geocoder;
let latlng = {lat: this.currentBusiness.latitude, lng: this.currentBusiness.longitude};
let that = this;
geocoder.geocode({'location': latlng}, function(results) {
if (results[0]) {
that.zoom = 11;
that.currentLocation = results[0].formatted_address;
//console.log(that.currentLocation);
} else {
console.log('No results found');
}
});
});
}
您必须重新分配"this",因为它丢失了参考
you have to reassign 'this' because it lost the reference
希望对您有帮助
这篇关于如何从角度2的纬度,经度中获取完整的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文