Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Geocode Components two countries

How is it possible to filter the results of the Google Geocode API and the use of the components parameter for two (or more) countries, without issuing another request.

Example:

  • http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&components=country:DE,AT&address=wien
    gives zero result, as there is no Wien in Germany and the AT after the comma is ignored
  • http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&components=country:AT,DE&address=wien
    is ok, because there is an Wien in Austria
  • http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&components=country:AT|country:DE&address=wien
    gives zero results, as the two component filters are outruling each other

Is there something in the documentation that I overread that makes it possible, or can't I make it at all?

Edit

I tried a workaround with setting the merged bounds of Germany and Austria, but that just weighs the results and not filters them, so I got a result which I didn't want with http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&components=bounds:55.058,17.161|46.372,5.866&address=new%20york. In this case I want a ZERO_RESULTS status.

like image 878
yunzen Avatar asked Aug 12 '13 09:08

yunzen


1 Answers

This is not currently possible. Please vote up issue #4233 if you want to see this happen.

For time being I can suggest three possible workarounds, none of them perfect:

  1. Make multiple requests and merge the result sets manually. This will give the best accuracy, but is obviously the slowest.
  2. Use the manually merged bounds trick in HerrSerker's question, then manually filter out results where the short_name of the address_components element with a types of country is not in your list of countries.
  3. Drop the component filter entirely and include "Austria OR Germany" in your search string. Again, you will want to manually filter the results.
like image 54
lambshaanxy Avatar answered Oct 17 '22 07:10

lambshaanxy