拖动标记后 Ng-map 获取地址
Ng-map get address after dragging marker
我正在使用 ng-map 在 angularjs 中使用 google 地图。我想在标记拖动结束后获得地址。我试图在他们的文档中找到但没有找到。他们的文档很好,但没有找到我想要的。尝试后,我在拖动结束后得到了纬度和日志。但我需要地址。所以我要做的是从标记获取地址,或者我可以将经纬度转换为地址。但我没有找到任何代码让地理编码器将经纬度转换为地址。这是我可以获取纬度和经度的代码:-
<ng-map>
<marker centered="true" position="current-location" draggable="true" on-dragend="getCurrentLocation()"></marker>
</ng-map>
这是方法:-
$scope.getCurrentLocation = function(){
$scope.pos = this.getPosition();
console.log($scope.pos.lat(),$scope.pos.lng());
}
拖动标记后请帮我找到地址
在线有一个指令可以进行反向地理编码。太棒了,你可以直接在你的代码中使用,达到将标记拖拽到有效地址后得到的lat/lng转换为有效地址的目的。
请看一下这个也有指令代码的tutorial。
你可以看看这个例子,并加以利用。
Google有自己的方式实现反向地理编码
文档:https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse
示例:http://plnkr.co/edit/rSKZR8?p=preview
this.doSth = function() {
geocoder.geocode({'location': this.getPosition()}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log(results[1]);
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
}
在函数$scope.getCurrentLocation()中,它接收一个参数,你可以用它来获取标记的位置(lat,lng)。
您的代码将是:
$scope.getCurrentLocation = function(event){
console.log(event.latLng.lat());
console.log(event.latLng.lng());
}
我正在使用 ng-map 在 angularjs 中使用 google 地图。我想在标记拖动结束后获得地址。我试图在他们的文档中找到但没有找到。他们的文档很好,但没有找到我想要的。尝试后,我在拖动结束后得到了纬度和日志。但我需要地址。所以我要做的是从标记获取地址,或者我可以将经纬度转换为地址。但我没有找到任何代码让地理编码器将经纬度转换为地址。这是我可以获取纬度和经度的代码:-
<ng-map>
<marker centered="true" position="current-location" draggable="true" on-dragend="getCurrentLocation()"></marker>
</ng-map>
这是方法:-
$scope.getCurrentLocation = function(){
$scope.pos = this.getPosition();
console.log($scope.pos.lat(),$scope.pos.lng());
}
拖动标记后请帮我找到地址
在线有一个指令可以进行反向地理编码。太棒了,你可以直接在你的代码中使用,达到将标记拖拽到有效地址后得到的lat/lng转换为有效地址的目的。
请看一下这个也有指令代码的tutorial。
你可以看看这个例子,并加以利用。 Google有自己的方式实现反向地理编码
文档:https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse
示例:http://plnkr.co/edit/rSKZR8?p=preview
this.doSth = function() {
geocoder.geocode({'location': this.getPosition()}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log(results[1]);
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
}
在函数$scope.getCurrentLocation()中,它接收一个参数,你可以用它来获取标记的位置(lat,lng)。
您的代码将是:
$scope.getCurrentLocation = function(event){
console.log(event.latLng.lat());
console.log(event.latLng.lng());
}