如何解决使用角度 10 中的纬度和经度从当前位置获取用户地址
我是 Angular 和开发的新手。谁能帮我解决这个任务?我搞砸了这个从当前位置获取用户地址的任务。当我使用标记放大或缩小地图时,我可以获得该位置的正确地址。但是当我在地图上拖放标记时我无法获得地址任何人都可以解决这个问题。
public mapReady(map) {
debugger
map.addListener("dragend",() => {
console.log(this.centerLatitude,this.centerLongitude);
this.apiloader.load().then(() => {
let geocoder = new google.maps.Geocoder;
let latlng = {
lat: this.centerLatitude,lng: this.centerLongitude
};
geocoder.geocode({
'location': latlng
},function(results) {
if (results[0]) {
this.currentLocation = results[0].formatted_address;
console.log(this.currentLocation);
} else {
console.log('Not found');
}
});
});
});
}
public centerChanged(coords: google.maps.LatLngLiteral) {
this.centerLatitude = coords.lat;
this.centerLongitude = coords.lng;
this.apiloader.load().then(() => {
let geocoder = new google.maps.Geocoder;
let latlng = {
lat: this.centerLatitude,lng: this.centerLongitude
};
geocoder.geocode({
'location': latlng
},function(results) {
if (results[0]) {
this.currentLocation = results[0].formatted_address;
console.log(this.currentLocation);
} else {
console.log('Not found');
}
});
});
}
private setCurrentLocation() {
if ('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition((position) => {
this.lat = position.coords.latitude;
this.lng = position.coords.longitude;
this.marlatitude = position.coords.latitude;
this.marongitude = position.coords.longitude;
this.zoom = 8;
this.centerLatitude = this.marlatitude;
this.centerLongitude = this.marongitude;
this.apiloader.load().then(() => {
let geocoder = new google.maps.Geocoder;
let latlng = {
lat: this.centerLatitude,lng: this.centerLongitude
};
geocoder.geocode({
'location': latlng
},function(results) {
if (results[0]) {
this.currentLocation = results[0].formatted_address;
console.log(this.currentLocation);
} else {
console.log('Not found');
}
});
});
console.log(position)
});
}
}
<div class="map">
<agm-map
#agmMap
[latitude]="centerLatitude"
[longitude]="centerLongitude"
[zoom]="zoom"
(mapReady)="mapReady($event)"
(centerChange)="centerChanged($event)">
<agm-marker
[(latitude)]="centerLatitude"
[(longitude)]="centerLongitude"
[markerDraggable]="draggable"
(dragEnd)="mapReady($event)"
(centerChange)="centerChanged($event)">
</agm-marker>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。