7

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.)?

Kara
  • 6,115
  • 16
  • 50
  • 57
jrdioko
  • 32,230
  • 28
  • 81
  • 120

5 Answers5

8
  • Street address is street_number and route
  • City is locality
  • State is administrative_area_level_1
  • ZIP is postal_code
  • Country is 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.

Sean
  • 321
  • 3
  • 6
  • 2
    Well it doesn't drop the unit number, it includes it (generally in `subpremise` from what I've seen). I can run a sample through and hit the majority of cases, but I was hoping there'd be some better way to get all or almost all addresses right (even if they have a `floor` or `room` or `premise`). – jrdioko Jun 15 '11 at 19:30
  • Correct the place object returned from the API does include a `subpremise` value which contains the Unit number (tested using an Australian address). – Bradley Flood May 27 '15 at 06:12
1

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.

expelledboy
  • 2,033
  • 18
  • 18
  • I'm working in Objective-C for an iOS app, but my question is about the API itself. The documentation gives a description for each field, but my problem is mapping that back to standard US address format. In other words, it sounds like US cities will always go in the `locality` field, but that's still ambiguous. `street_address` doesn't appear in responses to my test requests, and there's no explanation how to construct a valid street address from the remaining fields. – jrdioko Jun 13 '11 at 17:10
1

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.

rndapology
  • 142
  • 6
  • `formatted_address` is close, but I need to split it into three distinct fields: street address, city, and state code. Breaking on the commas is as close as I've been able to get, but I assume there's no guarantee on the format of `formatted_address`. – jrdioko Jun 13 '11 at 21:13
0

After many hours of working on it, I wasn't able to consistently extract the flat / room / sub premise. Having that detail was more important than being able to specifically separate it, so I got around it using this.

var componentForm = {
    locality: 'long_name',
    administrative_area_level_1: 'short_name',
    country: 'long_name',
    postal_code: 'short_name'
};

function fillInAddress(place) {
    for (var component in componentForm) {
        document.getElementById(component).value = '';
        document.getElementById(component).disabled = false;
    }
    for (var i = 0; i < place.address_components.length; i++) {
        var addressType = place.address_components[i].types[0];
        if (componentForm[addressType]) {
            var val = place.address_components[i][componentForm[addressType]];
            document.getElementById(addressType).value = val;
        }
    }
    var parts = $("#searchField").val().split(",");
    $("#street_number").val(parts[0]);
}

I've extracted the information from the auto complete as normal, although skipped "street_number" and "route". Then did a simple split on the auto complete value after selection and used the first portion, returning the street address as a whole (including factory / flat / premise and street name).

This work around gave me results that work well for what I need. Good luck!

AdheneManx
  • 306
  • 3
  • 11
0

I think you need to use 'route' for the street address.

I use the same service and from my experience 'route' is always the equivalent of a street address, even when the location is not actually a street!

I think you have already determined how to figure out the city name. etc. It is the same approach I take; have a look at a variety of API results for a few different locations and see which field gives you the most consistent results.

Mullins
  • 2,304
  • 1
  • 19
  • 18
  • `route` doesn't include the number at the beginning of the street address, that's in `street_number`. And in my testing unit numbers and other parts of the street address wind up in other fields, so `route` isn't a complete address. – jrdioko Jun 15 '11 at 19:28
  • Sorry I meant that `route` contains the Street NAME excluding the house number. I found that street name was mainly in `route` in my country. – Mullins Jun 15 '11 at 22:20