Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geocode API does not recognize address, although google maps does

I am using Geocode API on a project, where users have a text input to enter an address. This address is found using Google Maps API, however, Geocode API cannot find the address. The strange part is that it works for some addresses, but for some others it doesn't.

For example, the address Courchevel, Saint-Bon-Tarentaise, France can be found on Google Maps, but not with the Geocode URL: https://maps-api-ssl.google.com/maps/api/geocode/json?address=Courchevel%2C%20Saint-Bon-Tarentaise%2C%20France&sensor=false&client=gme-kickzag&signature=MY_SIGNATURE=, where MY_SIGNATURE is given correctly.

On the other hand, the address Basel, Switzerland works correctly: https://maps-api-ssl.google.com/maps/api/geocode/json?address=Basel%2C%20Switzerland&sensor=false&client=gme-kickzag&signature=MY_SIGNATURE=

Any answer is very much appreciated!

like image 782
Shend Avatar asked Aug 11 '26 11:08

Shend


1 Answers

You can use the Places Service and pass it a place ID. Only catch is you have to pass the service an instance of a map or an html element node. Here's an example:

// "map" is a google map you have created
var service = new google.maps.places.PlacesService(map);

var request = {
  placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4'
};

service.getDetails(request, callback);

function callback(place, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    var lat = results.geometry.location.lat(),
        long = results.geometry.location.lng();
    console.log('lat & long', lat, long);
  }
}

In my case since I am not using a map so I passed it an html node like

var details = document.getElementById('details');
var service = new google.maps.places.PlacesService(details);

To adhere to the terms, you cannot hide the element. However it appears the service doesn't augment it.

like image 110
inorganik Avatar answered Aug 13 '26 08:08

inorganik