Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ng-map get address after dragging marker

I am using ng-map to use google map in angularjs. I want to get address safter drag end of marker. I have tried to find in their documentation but did not found for that. Their documentation is good but did not found what i wanted. After trying i got the lat and log after drag end. But i need the address. So what i have to do is to get address from marker or i can convert lat & long to address. But i did not find any code for geocoder to convert lat long to address. Here is the code from where i can the lat & long :-

<ng-map>
    <marker centered="true" position="current-location" draggable="true" on-dragend="getCurrentLocation()"></marker>
</ng-map>

here is the method :-

$scope.getCurrentLocation = function(){
     $scope.pos = this.getPosition();
     console.log($scope.pos.lat(),$scope.pos.lng());
}

Please help me to find the address after dragging the marker.

like image 718
Bik Avatar asked Dec 25 '22 11:12

Bik


1 Answers

In the function $scope.getCurrentLocation(), it receives a parameter, you can use it to get the location (lat,lng) for the marker.

Your code would be:

$scope.getCurrentLocation = function(event){
        console.log(event.latLng.lat());
        console.log(event.latLng.lng());
}
like image 136
Kendall González Avatar answered Jan 05 '23 00:01

Kendall González