Blaze Blaze - 1 year ago 247
AngularJS Question

Ionic: Reverse Geocoding

I am integrating GPS Services into my application. I have added and injected the Cordova GPS plugin.
I am able to retrieve the longitude and the latitude as shown on the ngCordova documentation on gps. This is my approach:

.controller('geoLocationCtrl', function($scope,$window) {
$ = position.coords.latitude;
$scope.lng = position.coords.longitude;


My challenge is how can I use the above to return the current address, state and country of the user.

Answer Source

The process of turning a longitude and latitude into a human readable address is called Reverse Geocoding. Many map APIs support that like Google Maps and Here Maps. Here is how you can do it using Google Maps API

Add Google Maps JavaScript API

<script type="text/javascript" src=""></script>

Query the API: here is an angular controller sample

app.controller('geoLocationCtrl', function($scope, $window) {
  $window.navigator.geolocation.getCurrentPosition(function(position) {
    $scope.$apply(function() {
      $ = position.Coordinates.latitude;
      $scope.lng = position.Coordinates.longitude;

      var geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng($, $scope.lng);
      var request = {
        latLng: latlng
      geocoder.geocode(request, function(data, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          if (data[0] != null) {
            alert("address is: " + data[0].formatted_address);
          } else {
            alert("No address available");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download