Search code examples
google-geocodergoogle-geocoding-api

Google geocoding API - search in just one country


I am looking for geocodes with the google geocode-API:

http://maps.googleapis.com/maps/api/geocode/json?address=london%c2+UK&sensor=false

The problem is, that the input isn't very accurate (specially the street) and sometimes google mixes things up and ignores UK, because the street has a perfect match (as street and city) somewhere else. e.g. US.

Now i cannot solve this issue (input data), but I am wondering if there is a parameter, which forces google to search in UK and return no result instead of a completly wrong result.


Solution

  • You can add component filters in the url to constraint results. In this case you can use:

    http://maps.googleapis.com/maps/api/geocode/json?address=london%c2+UK**&components=country:UK**&sensor=false
    

    For more information about how to use component filtering see:

    https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering