Google geocoding API - search in just one country
Asked Answered
H

1

7

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.

Herschel answered 19/2, 2013 at 11:36 Comment(0)
K
13

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

Kilter answered 19/2, 2013 at 14:20 Comment(4)
thanks for your answer - it's working, but for my case: if the country is wrong (input), this will return as result the specified country.Herschel
You're right, as the api says:"A query containing a component filter will only return the geocoding results that match the filter. If no matches are found, the geocoder will return a result that matches the filter itself. ... Component filtering will return a ZERO_RESULTS response only if you provide filters that exclude each other."Kilter
Are you making this calls from javascript? If so, you may consider using the geocoder object from google maps api for javascript. You won't be able to filter results only to "bias" them, but you will get ZERO_RESULTS states. linkKilter
When we use it so we can't show not success message like alert("Geocode was not successful for the following reason: " + status);Reopen

© 2022 - 2024 — McMap. All rights reserved.