Daniel
Daniel

Reputation: 341

Understading google geocoding service component filters

I was testing the components filters when I came across something I was not expecting: using a filter will improve the results of some queries. The address I tested was "Avenida de Almirante Reis, 61 C/V.D, Lisboa".

Without the filter the result will only point to a Locality, while if I add a country filter it will point to an exact address.

Which leads me to doubt my knowledge on filters. The only modification a filter should do is to reduce the set of answers, not change it, which is what happens in this case.

I would like to know this because I'm using Google's Geocoding Service and will need to explain (to a certain degree) why I get the results I get, which means understanding this behaviour.

Thanks in advance.

Upvotes: 4

Views: 430

Answers (1)

miguev
miguev

Reputation: 4855

No and yes.

Component filters are meant to restrict results, not change them. Both your examples return just the country now, but these work:

http://maps.googleapis.com/maps/api/geocode/json?address=Avenida%20de%20Almirante%20Reis,%2061%20Lisboa http://maps.googleapis.com/maps/api/geocode/json?address=Avenida%20de%20Almirante%20Reis,%2061%20Lisboa&components=country%3aPT

However, see this Note in the Component Filtering documentation:

Note: Each address component can only be specified either in the address parameter or as a component filter, but not both. Doing so may result in ZERO_RESULTS.

It seems to be OK to repeat country, so the 2nd link works, although according to this note it'd be better to use this:

http://maps.googleapis.com/maps/api/geocode/json?address=Avenida%20de%20Almirante%20Reis,%2061&components=country%3aPT

But if you do the same with the street name, it does result in ZERO_RESULTS:

http://maps.googleapis.com/maps/api/geocode/json?address=Avenida%20de%20Almirante%20Reis,%2061%20Lisboa&components=country%3aPT%7Aroute%3AAvenida%20de%20Almirante%20Reis

Upvotes: 1

Related Questions