Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API Geocode Postal Code and set Country code?

I'm using this API call to Google Maps to get the latitude and longitude of a postal code

http://maps.googleapis.com/maps/api/geocode/json?address=2340&sensor=false

The postal code is in Australia. This API call returns locations all around the world with partial matching postal codes in the address.

Is there a parameter I can use to set the country to Australia?

Thanks

like image 362
Anagio Avatar asked Jul 31 '12 19:07

Anagio


People also ask

How do I get a zip code from Google Maps?

Or if you're travelling, and want to see the ZIP Code for your current location, there's a little a little circle button in the upper right corner of the map that will go to your current location and show the ZIP Code.

Is there any free Geocoding API?

positionstack - Free Address Geocoding & Maps API.

Is Geocoding API free Google?

The Geocoding API uses a pay-as-you-go pricing model. Geocoding API requests generate calls to one of two SKUs depending on the type of request: basic or advanced.


2 Answers

The correct way to do this is not via region biasing but rather using component filtering:

https://maps.google.com/maps/api/geocode/json
    ?components=country:AU|postal_code:2340
    &sensor=false

Some demonstrations:

  • 2340
  • 93274

Please note that if you use the components parameter, you don't need to specify the address parameter.

like image 119
Alix Axel Avatar answered Sep 28 '22 04:09

Alix Axel


The documentation says that Region Biasing is based on CcTLDs, which would make Australia au (haven't tried it myself).

Although it also states this:

Note that biasing only prefers results for a specific domain; if more relevant results exist outside of this domain, they may be included.

like image 22
geocodezip Avatar answered Sep 28 '22 02:09

geocodezip