I am attempting to obtain the address components using the Google Maps API however am unable to properly parse results. My code is as follows:
// Ajax C
I'm assuming what you are doing is a reverse geocode.
The object returned looks something like this (from the example):
{
"address_components": [
{
"long_name": "Grand St/Bedford Av",
"short_name": "Grand St/Bedford Av",
"types": [
"bus_station",
"transit_station",
"establishment"
]
},
{
"long_name": "Williamsburg",
"short_name": "Williamsburg",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Brooklyn",
"short_name": "Brooklyn",
"types": [
"sublocality_level_1",
"sublocality",
"political"
]
},
...
There is no direct way to access a result's street, house number etc. because each part of the address can be several types at the same time. You would have to iterate over the address_components
and filter according to what you need.
Here's another Stackoverflow thread covering this topic: get city from geocoder results?