Geocode API does not recognize address, although google maps does

2.5k views Asked by At

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!

2

There are 2 answers

2
inorganik On

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.

0
Michael Whatcott On

The subject of searching for addresses is complex. Some things that are difficult include:

There is a lot of useful information about addresses and searching in the FAQ articles from SmartyStreets.

As for your question, you have brought up an interesting case. (It is not quite clear what your question is, but on the theme of Google APIs...) Google has many products, which were created to solve specific problems. In one case, it might be good for Google to help users explore an area: they want to find a region and show restaurants and events, etc. In a different case, it would be good for Google to find an exact geocode location. Thus, it is important for Google API users to think through their problem and goals, and make a correct decision about which tools to use. You might find the Google API Picker to be useful.

Fair disclosure: I work for SmartyStreets, a company which focuses on address validation.