Reverse geocoding Google

Have you ever seen a web site that seemed to know where you were located? I'm not talking about a map,but the actual name of the location? This is done with a process called "Reverse Geocoding." Whereas geocoding refers to translating a human-readable address into a longitude/latitude pair,reverse geocoding is,well,the opposite of that. Given a longitude/latitude pair,what would be the description of that location. In this blog post I'll show a simple example of this process. My example application will attempt to report the city and state you live in.

Once again I'll be making use of Google for my example. One of the services of the Google Maps API is geocoding as well as reverse geocoding. Their reverse geocode API needs a longitude and latitude,we can get that easily enough using Geolocation. Here is a snippet of code that begins the process:

Please note that in this demo,if the user doesn't support geolocation I'm not going to do anything else. They won't get an error though and won't know what they are missing.

Once we have the longitude and latitude,we then fire off a request to the geocode service.

As with our initial geolocation support,all I care about here is a success. If anything goes wrong,I don't care and I just ignore it.

So,here comes the difficult part. The result was from the geocode call is fairly complex. You get an array of results ordered by the quality of the match. If you check the docs,you can see an example of this. Each individual result is also fairly complex. You get an array of address parts that represent,obviously,parts of an address. If you read the "Address Component Types" section of the docs,you can see an explanation of the types of address parts. Each part has one or more of these types applied as a tag.

Based on my reading of the spec,I determined I could get the city when the tag was "locality" and the state when the tag was "administrative_area_level_1." This is US-centric and I've not done any testing yet with other countries.

Given that I knew which tags to look for,I decided to work with the first result and see if I could match those tags:

Again,if there isn't a match I don't throw an error. Since this is simply window dressing for the site it doesn't really matter if we don't get a match. Want to see this in action? Check out the demo below.

You might also like
Android No-Permissions Reverse Shell
Android No-Permissions Reverse Shell
How to create a simple Google Map app in Android
How to create a simple Google Map app in Android
Barcamp Bangalore 13: Reverse Engineering an Android app
Barcamp Bangalore 13: Reverse Engineering an Android app ...

Doyle Park...just up the street from my

by bikeriderdude

Office on Sonoma Avenue (towards Farmer's Lane).
Be great if you can bring a kid. We'll talk before then, but I'm pretty sure I can get my whole family to come.

Andrew Diamond Placemark Manager
Mobile Application (Andrew Diamond)
  • Import and Export KML/KMZ
  • Create and preserve folders.
  • Easily use saved locations to quickly get driving routes to destinations using Google Maps, Waze, or any other preferred Navigation application.

7 Game of Thrones Apps That Will Get You Through the Much-awaited Winter  — Gizmodo India
.. or Winterfell, you get a dialog box, which asks you to buy more maps. Unfortunately, you can't dismiss the dialogue box, leading to the obstruction of the cartography. ..

Flagstaff's rocky lava field became a little piece of the moon  — azcentral
If American know-how could put a man on the moon, the man should bring back rocks to study. The government agreed, and in 1963, the .. Volcanoes were chosen because of the moon's volcanic history, the test site for its impact craters.

Andrew Diamond My Ten Twenty
Mobile Application (Andrew Diamond)
  • Adjust polling frequency to what you need.
  • Select online or offline reverse geocoding engine.
  • Completely free, and no ads!

Missing in Alaska without a trace  — Anchorage Daily News
The official version of events, according to a still active missing person's bulletin from the Alaska State Troopers is that Griffis went into the wild "to test out a survival 'cocoon' that he had invented.

Popular Q&A

Is reverse Google Geocoding API of freely usable?

You can use the Maps API for free to geocode, but you need to embed the map and call geocode within a client side web page.

What is the best service for reverse geocoding (other than Google's)? We need to do it server-side, and without attaching a map view. - Quora

Factual (my shop) does a REST-based API: 10k free per day -- paid pricing above that varies, based on the minimum number of calls per month.

Related Posts