Software Archive
Read-only legacy content
17060 Discussions

reverse geocoding latitude and longitude

Oonagh_M_1
Beginner
723 Views

i currently have the following code in my JavaScript file. When i run the app, the 'reverse geocode' button appears, which i click on. Once i click on the button the following error appears: "Geocoder failed due to: ZERO_RESULTS. Am i missing something?

This has been testing on my mobile device and the error is also appearing. Any help would be appreciated. Thank you.

 

 

function click_button_reverseGeo(currentLatitude, currentLongitude){
  var latlng = new google.maps.LatLng(currentLatitude, currentLongitude);
  var geocoder = new google.maps.Geocoder();
  geocoder.geocode({'latLng': latlng}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      if (results[1]) {
        alert(results[1].formatted_address);
      } else {
        alert('No results found');
      }
    } else {
      alert('Geocoder failed due to: ' + status);
    }
  });
}
0 Kudos
1 Reply
Michael_O_2
New Contributor I
723 Views

Hello.

Make a call to maps.googleapis.com/geocode/xml from  your server after getting the latlng.

Geocoding service will give you appropriate results when you send a request from your back end.

0 Kudos
Reply