I'm using Google's Geocoding API to process free-form address data and am trying to make sense of the results (subpremise
, administrative_area_level_2
, etc.). At this point I'm only interested in addresses in the US, and would like to format the results as a street address, city, and state code. The state code seems straightforward (administrative_area_level_1
), but the others are more vague. Is city locality
or sublocality
or both or even more? The street address itself seems like it could be any number of combinations of the other fields.
Ideally, I'd like to just take the formatted_address
, strip off the city, state, zip, and country code, and keep what is left as my "street address". Are there any guidelines or recommendations for handling all these fields, at least for the majority of cases (regular addresses, addresses with unit numbers, etc.)?
While HTML5 geolocation provides the latitude and longitude, the Google Maps Geocoding API can convert those into a complex structure of address components. The combination of the two gives us door-level accuracy in most cases.
According to Google's API Usage and Billing page, there is a limit of 50 requests per second. If you exceed this amount, subsequent requests to the API will fail with the OVER_DAILY_LIMIT or OVER_QUERY_LIMIT status code and the geocoded data will not be returned.
The geocoder does its best to provide a street address that is readable for both the user and locals. To achieve that goal, it returns street addresses in the local language, transliterated to a script readable by the user if necessary, observing the preferred language.
Enable Geocoding API In your Google Cloud Platform Console, go to APIs & Services → Dashboard → Enable APIs & Services at the top and choose Maps JavaScript API from the API Library. This will open up the Maps JavaScript API page and Enable it.
street_number
and route
locality
administrative_area_level_1
postal_code
country
Note that Google ignores any kind of unit number (e.g. 'Apt 13A'). You'll have to add that back in yourself.
Running a sample of your data through the geocoder and checking the results manually should confirm that you're getting what you need.
The documentation seems to cover what the various fields mean quite clearly.
You havent said what language you are working in, but I think this will help.
I am doing reverse geocoding on Nearlots.com in the search pages. Basically, the user drops a marker somewhere on the map and I print an address in a search box.
I am simply printing 'formatted_address' and giving up if it's not there. This will give you something like this: "275-291 Bedford Ave, Brooklyn, NY 11211, USA". This is more than sufficient - you can always strip out the USA at the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With