Matt
Posts: 0
Joined: Tue Oct 16, 2012 7:26 pm

Google Reverse Geocode results

I am attempting to read data from a google reverse geocode. Using the Google API, I am getting back a json response that looks something like this:

{
"results": [
{
"formatted_address": "23550 26 Mile Rd, Macomb, MI 48042, USA",
"types": [
"street_address"
],
"address_components": [
{
"types": [
"street_number"
],
"long_name": "23550",
"short_name": "23550"
},
{
"types": ["route"],
"long_name": "26 Mile Rd",
"short_name": "26 Mile Rd"
},
{
"types": [
"administrative_area_level_3",
"political"
],
"long_name": "Macomb",
"short_name": "Macomb"
},
{
"types": [
"administrative_area_level_2",
"political"
],
"long_name": "Macomb",
"short_name": "Macomb"
},
{
"types": [
"administrative_area_level_1",
"political"
],
"long_name": "Michigan",
"short_name": "MI"
},
{
"types": [
"country",
"political"
],
"long_name": "United States",
"short_name": "US"
},
{
"types": [
"postal_code"
],
"long_name": "48042",
"short_name": "48042"
}
],
"geometry": {
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 42.71895798029149,
"lng": -82.8724090197085
},
"southwest": {
"lat": 42.71626001970849,
"lng": -82.8751069802915
}
},
"location": {
"lat": 42.717609,
"lng": -82.873758
}
}
},
{
"formatted_address": "Macomb, MI 48042, USA",
"types": [
"postal_code"
],
"address_components": [
{
"types": [
"postal_code"
],
"long_name": "48042",
"short_name": "48042"
},
{
"types": [
"administrative_area_level_3",
"political"
],
"long_name": "Macomb",
"short_name": "Macomb"
},
{
"types": [
"administrative_area_level_2",
"political"
],
"long_name": "Macomb",
"short_name": "Macomb"
},
{
"types": [
"administrative_area_level_1",
"political"
],
"long_name": "Michigan",
"short_name": "MI"
},
{
"types": [
"country",
"political"
],
"long_name": "United States",
"short_name": "US"
}
],
"geometry": {
"bounds": {
"northeast": {
"lat": 42.7181329,
"lng": -82.8560809
},
"southwest": {
"lat": 42.62835,
"lng": -82.9769081
}
},
"location_type": "APPROXIMATE",
"location": {
"lat": 42.6937328,
"lng": -82.9178838
},
"viewport": {
"northeast": {
"lat": 42.7181329,
"lng": -82.8560809
},
"southwest": {
"lat": 42.62835,
"lng": -82.9769081
}
}
}
},
{
"formatted_address": "Macomb, MI, USA",
"types": [
"administrative_area_level_3",
"political"
],
"address_components": [
{
"types": [
"administrative_area_level_3",
"political"
],
"long_name": "Macomb",
"short_name": "Macomb"
},
{
"types": [
"administrative_area_level_2",
"political"
],
"long_name": "Macomb",
"short_name": "Macomb"
},
{
"types": [
"administrative_area_level_1",
"political"
],
"long_name": "Michigan",
"short_name": "MI"
},
{
"types": [
"country",
"political"
],
"long_name": "United States",
"short_name": "US"
}
],
"geometry": {
"bounds": {
"northeast": {
"lat": 42.7181329,
"lng": -82.8561299
},
"southwest": {
"lat": 42.627811,
"lng": -82.9769081
}
},
"location_type": "APPROXIMATE",
"location": {
"lat": 42.6651965,
"lng": -82.92864279999999
},
"viewport": {
"northeast": {
"lat": 42.7181329,
"lng": -82.8561299
},
"southwest": {
"lat": 42.627811,
"lng": -82.9769081
}
}
}
},
{
"formatted_address": "Macomb, MI, USA",
"types": [
"administrative_area_level_2",
"political"
],
"address_components": [
{
"types": [
"administrative_area_level_2",
"political"
],
"long_name": "Macomb",
"short_name": "Macomb"
},
{
"types": [
"administrative_area_level_1",
"political"
],
"long_name": "Michigan",
"short_name": "MI"
},
{
"types": [
"country",
"political"
],
"long_name": "United States",
"short_name": "US"
}
],
"geometry": {
"bounds": {
"northeast": {
"lat": 42.897541,
"lng": -82.7059762
},
"southwest": {
"lat": 42.447055,
"lng": -83.102891
}
},
"location_type": "APPROXIMATE",
"location": {
"lat": 42.7168759,
"lng": -82.82097399999999
},
"viewport": {
"northeast": {
"lat": 42.897541,
"lng": -82.7059762
},
"southwest": {
"lat": 42.447055,
"lng": -83.102891
}
}
}
},
{
"formatted_address": "Michigan, USA",
"types": [
"administrative_area_level_1",
"political"
],
"address_components": [
{
"types": [
"administrative_area_level_1",
"political"
],
"long_name": "Michigan",
"short_name": "MI"
},
{
"types": [
"country",
"political"
],
"long_name": "United States",
"short_name": "US"
}
],
"geometry": {
"bounds": {
"northeast": {
"lat": 48.28764289999999,
"lng": -82.413474
},
"southwest": {
"lat": 41.696118,
"lng": -90.4181358
}
},
"location_type": "APPROXIMATE",
"location": {
"lat": 44.3148443,
"lng": -85.60236429999999
},
"viewport": {
"northeast": {
"lat": 48.2627089,
"lng": -82.413474
},
"southwest": {
"lat": 41.696118,
"lng": -90.4181358
}
}
}
},
{
"formatted_address": "United States",
"types": [
"country",
"political"
],
"address_components": [
{
"types": [
"country",
"political"
],
"long_name": "United States",
"short_name": "US"
}
],
"geometry": {
"bounds": {
"northeast": {
"lat": 71.389888,
"lng": -66.94976079999999
},
"southwest": {
"lat": 18.9110642,
"lng": 172.4546966
}
},
"location_type": "APPROXIMATE",
"location": {
"lat": 37.09024,
"lng": -95.712891
},
"viewport": {
"northeast": {
"lat": 49.38,
"lng": -66.94
},
"southwest": {
"lat": 25.82,
"lng": -124.39
}
}
}
}
],
"status": "OK"
}

The question is, when mapping the response, how can i specify the different types. For instance, I want to get out the type of "street_number" or "postal_code" from "address_components".

Also, if there is another route to reverse geocode an address from Tiggzi, I would be willing to explore that as an option.

Thank you!
Matt

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Google Reverse Geocode results

This is what I get when I used the JSON you provided:

Image

Is typep[0] -- the street_number and type[1] -- is the postal code?

Matt
Posts: 0
Joined: Tue Oct 16, 2012 7:26 pm

Google Reverse Geocode results

Per google's API documentation (at: : https://developers.google.com/maps/do...)

The following types are supported and returned by the HTTP Geocoder:

street_address indicates a precise street address.
route indicates a named route (such as "US 101").
intersection indicates a major intersection, usually of two major roads.
political indicates a political entity. Usually, this type indicates a polygon of some civil administration.
country indicates the national political entity, and is typically the highest order type returned by the Geocoder.
administrative_area_level_1 indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. Not all nations exhibit these administrative levels.
administrative_area_level_2 indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels.
administrative_area_level_3 indicates a third-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
colloquial_area indicates a commonly-used alternative name for the entity.
locality indicates an incorporated city or town political entity.
sublocality indicates an first-order civil entity below a locality
neighborhood indicates a named neighborhood
premise indicates a named location, usually a building or collection of buildings with a common name
subpremise indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a common name
postal_code indicates a postal code as used to address postal mail within the country.
natural_feature indicates a prominent natural feature.
airport indicates an airport.
park indicates a named park.
point_of_interest indicates a named point of interest. Typically, these "POI"s are prominent local entities that don't easily fit in another category such as "Empire State Building" or "Statue of Liberty."
In addition to the above, address components may exhibit the following types:

post_box indicates a specific postal box.
street_number indicates the precise street number.
floor indicates the floor of a building address.
room indicates the room of a building address.

The formatting on the copy and paste is broken. Probably better to look at the website listed above. It's not so much an index (the type) but a name.

Thanks!
-Matt

Matt
Posts: 0
Joined: Tue Oct 16, 2012 7:26 pm

Google Reverse Geocode results

It may make more sense if you try the rest call yourself from my app at:

http://project.tiggzi.com/mobile-fram...

Thanks again!
-Matt

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Google Reverse Geocode results

I guess I'm not clear when you say "I want to get out the type of "street_number" or "postal_code" from "address_components"... do you want to map those values to components on a page?

Matt
Posts: 0
Joined: Tue Oct 16, 2012 7:26 pm

Google Reverse Geocode results

Yes, the ultimate goal is to extract the current address (address, street, city, state, postal code) and complete the fields on a page in my project that I have linked above.

-Matt

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Google Reverse Geocode results

Have you tried mapping those fields to the components on the page or that didn't work?

Matt
Posts: 0
Joined: Tue Oct 16, 2012 7:26 pm

Google Reverse Geocode results

I'm not sure how I should go about doing that. When I do a "Populate from Sample Response" I get back the following: Image

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Google Reverse Geocode results

Hello! Try to map "result" on localStorage and then on Success event ran Custom JS which will get that result from localStorage (here is an example https://developers.google.com/maps/do...)

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Google Reverse Geocode results

Just to add to what Marina said.

It's interesting JSON in a sense that the actual name such as 'street_number' are inserted into types[..]. So, when you go over the array, you would need to check what type is it and then print it. For example, I just printed everything and got this:

Image

As you can see, street_number is the first in the types[].

Return to “Issues”