How to map google Geocoding API results to simple City, Region, Country - json

I have some markers on a map and when the user click them I use the google geocoder to get the address information. The issue is the format that Google returns this data. I want to display the address in a consistent format such as
Vancouver, British Columbia, Canada
Seattle, Washington, United States
Sydney, New South Wales, Australia
does any one know a simple way to parse this data so I end up with some nice simple json like
{"city":"Vancouver", "region":"British Columbia", "country":"Canada"}
Thanks.

Oh man, the days when I thought political geography was this simple were sweeter days. If Google could return data like this, they surely would. Instead you get a mess of locality, sublocality, administrative_area_level_*, country, etc.
To illustrate this, consider the following:
http://maps.googleapis.com/maps/api/geocode/json?address=11215&sensor=false
http://maps.googleapis.com/maps/api/geocode/json?address=10010&sensor=false
For Manhattan, you're in okay shape. You get the borough (Manhattan), the city (New York), the county (New York), and the state (New York). For Brooklyn, things aren't so clean. You get the borough (Brooklyn), the county (Kings), and the state (New York).
Now if you go a little ways out onto Long Island, you get more fun:
http://maps.googleapis.com/maps/api/geocode/json?address=40.723464,%20-73.716282&sensor=false
In this case you get the village (Floral Park), the town (Hempstead), the county (Nassau), and the state (New York), but everything is kind of muddled up.
This is the variation within 20 miles in one state. If you move out of that, you can count on even less. In the UK, what most of what we'd want to see as London, will be some smaller borough of Greater London.
Google provides a deep and rich taxonomy to deal with this variation, but you will still need to apply your own rules to make sense of it (often at the state by state and country by country level)

Related

Different placeID gives the same address information

Below two placeID's gives the same address.
1. EicyMDEgU291dGggTG93cnkgU3RyZWV0LCBTbXlybmEsIFROLCBVU0EiMRIvChQKEgm7_A4lPAxkiBEptR2cpqTb1xDJASoUChIJT4MxvQIMZIgRENDVZ6XiGTc
2. ChIJBbYyJDwMZIgR1TtBueaig5w
PlaceID1 was returned when the address searched using the autocomplete was " 201 South Lowry Street" and PlaceID2 was returned when the address searched using the autocomplete was " Goodwill Industries of Middle Tennessee 201 South Lowry Street".
Even though the above addresses are different, the place details API gives the same address information.
https://maps.googleapis.com/maps/api/place/details/json?place_id=EicyMDEgU291dGggTG93cnkgU3RyZWV0LCBTbXlybmEsIFROLCBVU0EiMRIvChQKEgm7_A4lPAxkiBEptR2cpqTb1xDJASoUChIJT4MxvQIMZIgRENDVZ6XiGTc&key=API_KEY
https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJBbYyJDwMZIgR1TtBueaig5w&key=API_KEY
Question :
1. Why is the same address which is of the street returned for two different placeID's?
2. The location returned by places Details API is correct but the address is of the street.
Below are few more examples where I observed same scenarios. Could you please brief on the below mentioned examples also?
PlaceID : ChIJZ2fZgcNVZIgRRY-uzGW9IBc and ChIJi15Hp8RVZIgRojWuKm_aG3M returned the same address as "2008 Memorial Boulevard Springfield Tennessee United States 37172", but the straight line distance between the two places is approximately 154 meters.
PlaceID : EiBBbm5leCBBdmVudWUsIE5hc2h2aWxsZSwgVE4sIFVTQSIuKiwKFAoSCd8ldk-TYWSIEZbufa-nQvmSEhQKEgk9kOsTMuxkiBGg2umh0Lk_fQ and ChIJ9ynrOIthZIgR-_7_cmwzeXo returned the same address as "3736, Annex Avenue Nashville Tennessee 37209" , but the straight line distance between the two places is approximately 6.92 meters.
PlaceID : ChIJTZvXpuJ7ZIgR8GqA7eDu5oY and ChIJ3ZUKweJ7ZIgRBjj8OqdMm5E returned the same address as "1777, Galleria Boulevard Franklin Tennessee 37067 " , but the straight line distance between the two places is approximately 12.24 meters.
PlaceID : EicyMDEgU291dGggTG93cnkgU3RyZWV0LCBTbXlybmEsIFROLCBVU0EiMRIvChQKEgm7_A4lPAxkiBEptR2cpqTb1xDJASoUChIJT4MxvQIMZIgRENDVZ6XiGTc and ChIJBbYyJDwMZIgR1TtBueaig5w returned the same address as "201 S Lowry St, Smyrna, TN 37167, United States " , but the straight line distance between the two places is approximately 97 meters.
Please note that it's possible for each place or feature to have similar addresses. This is why the Places API used Place IDs instead to uniquely identify the place/feature. As per this doc:
Place IDs uniquely identify a place in the Google Places database and
on Google Maps.
Below is my investigation on the addresses you have mentioned:
The place ID, ChIJZ2fZgcNVZIgRRY-uzGW9IBc, is of type, premise. As per the Address Types doc here:
Premise indicates a named location, usually a building or collection
of buildings with a common name.
If you think that a collection of building should not have the same address as the Place ID, ChIJi15Hp8RVZIgRojWuKm_aG3M, then I suggest that you report this Maps Data issue. (I'll put some more details on how to report Maps Data issues below)
The address returned for EiBBbm5leCBBdmV...iBGg2umh0Lk_fQ is an address of a route (Annex Ave, Nashville, TN 37209, USA), which is not the same as the the second Place ID's (ChIJ9ynrOIthZIgR-_7_cmwzeXo) address (3734 Annex Ave, Nashville, TN 37209, USA).
For the Item #3, what I can see is that the place ChIJTZvXpuJ7ZIgR8GqA7eDu5oY is a street_address while the other feature (ChIJ3ZUKweJ7ZIgRBjj8OqdMm5E) is a point_of_interest. These two features does not seem to be related so I believe that this is another Maps Data issue which can also be reported.
The feature, EicyMDEgU29...ENDVZ6XiGTc, on the other hand appears to be an inferred street address from a range of addresses. While the place, ChIJBbYyJDwMZIgR1TtBueaig5w, is the actual point_of_interest that's on that same street address. Note that the point of interest may close or move to a new location, but, the street address most likely won't change.
For Maps Data issues, this can be reported using the "Report a
Problem" or "Send feedback" link on the bottom right corner on
maps.google.com or in the Google Maps for Mobile Application. To learn
more, please see this guide. But for Maps Data that are added
using Google My Business, this can be modified directly by the
business owners themselves on their Google My Business account.
I hope this helps!

Geocode returns postal_code null for certain address

Geocode returns postal_code value null for certain addresses and I am not able to do reverse address lookup to retrieve the zip at that level.
An example address is "Peachtree Dunwoody Road, Atlanta, GA, United States"
There is no street number; Dunwoody is also a city name in vicinity. It is not happening for all two words street names, but happening only if one of the word(second one in the street name) is also a city name.
It works for most of the cases but just a few certain types ie "Peachtree Street Northwest, Atlanta, GA, United States"
The search is for "address".
geoLocationScript: "https://maps.googleapis.com/maps/api/js?",
geoLocationSensor: "sensor=false",
Is it a google glitch? and Is there any work around?
Zip codes actually only correspond to mailing routes. "Peachtree Dunwoody Road, Atlanta, GA, United States" isn't a mailing address and as such Google is trying to give you the best results it can, balancing exactness with usefulness. It's likely that "Peachtree Dunwoody Road" traverses multiple zip codes, and Google returns a pin at a geometric center for the road (try the search in Maps) but doesn't try to guess a zip code. Zip codes can be complicated and it's probably best not to make a guess unless the entire street is contained in one zip code. For instance, sometimes, the east side of a road has one zip code but the west side has a different zip code.
As for whether there is a workaround or not, I believe the answer is no. To illustrate, you might look at the SmartyStreets demo site and fill in the address components as much as possible. I just tried "Peachtree Dunwoody Road, Atlanta, GA, United States." While I was typing, SmartyStreets suggested the following three results:
Peachtree Dunwoody Rd, Atlanta GA
W Peachtree Dunwoody Rd, Atlanta GA
Peachtree Dunwoody Rd NE, Atlanta GA
Full disclosure: I worked for SmartyStreets, an address validation company.
Some location entries returned by the geocoder won't have postal_codes. The response for "Peachtree Dunwoody Road, Atlanta, GA, United States" is of type "GEOMETRIC_CENTER".
A "road" doesn't necessarily have a postal code (it isn't a postal address).

Regions of England in Google Maps API

I have a list of latitude/longitude which point to some cities in England.
For each of these coordinates I want to get the region they belong to.
By region, I mean one of these: https://en.wikipedia.org/wiki/Regions_of_England
For instance: For coordinates (53.38112, -1.47008), ie. Sheffield, I need to find Yorkshire and the Humber.
To achieve this, I tried to use Google Reverse Geocoding API:
https://maps.googleapis.com/maps/api/geocode/json?latlng=53.38112,-1.47008&key=
Google then tells me that:
country is United Kingdom
administrative_area_level_1 is England, which is a State (or kind of)
administrative_area_level_2 is South Yorkshire, which is a County
administrative_area_level_3 is Sheffield District, which is a District
So Google returns me the correct State, County and District. However, Region is missing.
Is there any way to obtain it?
Looking at the documentation I don't think the Google API returns such information.
An alternative way to get round this would be to build a list of which counties belong in which of the 9 regions and then look up the region based on the county name. Obviously, this would be a bit of work on your part putting all the county names into a list.
While this doesn't directly answer your query, you could use a set of polygons which trace the regions and a point in polygon algorithm (this example is in PHP but the algorithm exists in many languages) which would allow you to check which of the regions any latitude and longitude is in

Google maps geocoder state bias

I have a google maps application where users can search by Country, State, City or a street address. Users may be anywhere in the world and they may be searching for anywhere else in the world, not just within their own country.
I need the geocoder to have a bias such that if a state is entered (without the country) it geocodes to the state and not to a city with the same name. Our application prioritises countries first, then states, then cities etc... however the geocoder is not doing the same.
Eg. I want to search for "Victoria" which is a state within Australia.
http://maps.googleapis.com/maps/api/geocode/json?address=victoria shows Victoria, BC, Canada.
http://maps.googleapis.com/maps/api/geocode/json?address=victoria&region=au shows the state of Victoria in Australia however I cannot include the region as my users may be anywhere in the world so I have no way of knowing which region they are searching for.
I have looked at "administrative levels" and also "types" but I cannot find a solution which suits my needs of simply prioritising in the order country > state > city.
I ideally want something like this:
maps.googleapis.com/maps/api/geocode/json?address=victoria&components=administrative_area:WILDCARD
OR
maps.googleapis.com/maps/api/geocode/json?address=victoria&types=administrative_area_level_1
Of course neither of these solutions work but I hope they illustrate what I am trying to achieve.
Any suggestions?
Thanks,
Nicole
You can do a query without specifying the address, use
...?components=administrative_area:victoria
and then iterate over the results.address_components to pick out ones where the types include administrative_area_level_1
Update: I noticed that depending on the search term provided to administrative_area, google is using some kind of heuristics to determine the certainty of the results. If there's a clear winner, then only 1 result is shown. If the matching is similar for a group of locations, then you will get several. So when there's several results, you can pick towards a higher or lower administrative_area_level to suit your needs.

Is there a numeric road identifier in google maps?

I'm looking for a way to identify roads or streets on google maps.
I don't need the road name, just an identifier for a road. And I don't really care if GPS coordinate is really on the road as long as the results are consistent.
I need this in order to determine if two GPS coordinates are on the same road.
Now I know I can compare the road name between the two coordinates using geocoder but In some cases the road name is null, and I actually don't care about the name itself.
Is there any road ID that I can get using a geocoder ?
What do you mean by the 'same road'?
A road can have many different names and designations at the same time and over its length.
Consider Route 66 do you want to be considered to be on the same road if you are on the same road if your two locations are on route 66 near Los Angeles and Chicago or is it a series of different roads as wends its way through the cities en-route?
Should a road have a different id if has an arbitrary name change as it goes round a bend or crosses from one town to the next?