Search code examples
google-mapsgoogle-maps-api-3geocodinggoogle-geocodergeocode

Google geo code API not filtering results for Luxembourg


I am filtering results for country code LU. Still getting results for US

https://maps.googleapis.com/maps/api/geocode/json?address=4321%2CLU&components=country%3ALU

Am I doing anything wrong here?


Solution

  • Documentation says that you cannot use country in both address and component filter. Doing that you can get unpredictable behavior.

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

    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.

    So, your query should be

    https://maps.googleapis.com/maps/api/geocode/json?address=4321&components=country%3ALU&key=YOUR_API_KEY

    Not sure what means 4321. If this is a postal code, I think it is missing from Google database, because

    https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A4321%7Ccountry%3ALU&key=YOUR_API_KEY

    returns ZERO_RESULTS.