ABTUK Webmaster
ABTUK Webmaster

Reputation: 21

How to prevent Google geocoder incorrectly locating "European Union" as being in the USA?

I'm using https://maps.gstatic.com/maps-api-v3/api/js/19/4/intl/en_gb/geocoder.js

geocoder.geocode({"address":"European Union"}, ... 

returns New York, USA as its location !!

What changes, additional parameters, etc must I use to receive a more rational location ? Note: geocoder.geocode({"address":"EU"}, ... works fine, as do all country names I have tried.

Regards, Pete

Upvotes: 2

Views: 956

Answers (3)

Nick Carpenter
Nick Carpenter

Reputation: 61

I hope I'm not stating the obvious, but the European Union isn't a place that you can stick a map marker on!

It's an economic partnership between 28 different countries in and around the continent of Europe (yes, I know - some people from an English speaking country that isn't England do think that Europe is a country).

If you add EU for the region bias to the Google geocoder it will prioritise results for the Basque region (which is in Spain). You can look all the IANA Language Regions here: http://www.iana.org/assignments/language-subtag-registry.

You're trying to geocode a collection of countries as a single entity - it's not going to work no matter how many bug reports you file.

Upvotes: 1

ABTUK Webmaster
ABTUK Webmaster

Reputation: 21

I'll take your word for it that the New York location is that of an EU foreign embassy. And I hadn't noticed that a request for address EU returned the co-ordinates of a village in France named Eu (as opposed to a more generic location within Europe).

Including region EU within the geocode request appears to have no effect on the result. For example, the following request returns the location of Naples in Italy. But if I change IT to EU, or omit region completely, the location returned is for Naples in Florida:

"address":"Naples","region":"IT"

Google geocoder appears to accept any 2-character combination for region - and simply ignores any it does not recognise. It looks like "EU" is one such, despite it being listed since 2009 as an IANA language region subtag.

Any other ideas? Or should I raise this directly with Google?

Upvotes: 0

not_a_bot
not_a_bot

Reputation: 2362

The New York location you got is the European Union foreign embassy for the US. You can't make changes to the library, so you'll just have to change what you're passing into the geocoder. If you're trying to geocode for countries in the EU, you'd have to pass in each country you're interested in. Just a note, when I try geocoding "Eu", I get Eu, Seine-Maritime, which is located in France.

You can also put EU as the region for the GeocodeRequest object literal before passing it to Geocode.geocode() as documented here: https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingRequests

If you're working with JavaScript and HTML, you can use region code biasing to specify EU as the region for the Google map API in the script source (although the example below uses ES, but the idea is the same): https://developers.google.com/maps/documentation/javascript/examples/geocoding-region-es

Upvotes: 3

Related Questions