Search code examples
javascriptangularjsgoogle-maps-api-3ng-map

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.


Solution

  • There is a directive online that does the reverse geocoding. It is great and you can directly use in your code to serve the purpose of converting the lat/lng obtained after dragging the marker to a valid address.

    Please take a look at this tutorial that has the directive code too.