Reverse Geocoding


Unless you are displaying a map, providing an address or nearby points of interest is more tangible than latitude and longitude.

Reverse geocoding is the process of reverse-coding a point location to fetch a readable address and place name. It is widely used in combination with location-based services (LBS) to retrieve local weather data or business information, as well as by public safety services such as Enhanced 911. Such information is not immediately available, but there are free services that provide it.

The Yahoo! Geocoding API is well documented and reliable. You need to apply for an application ID that is required as an argument in your requests. It is not exclusive to mobile use and can be used in the browser, assuming it has a way to detect location. Go to and read the “How Do I Get Started” section to request an ID. You need to log in with a Yahoo! account and fill out the form. Provide the URL of a website, even though it will not be used on the device.

First, add the permission to go out to the Internet:

<uses-permission android:name=”android.permission.INTERNET” />

In this example, I am receiving the latitude and longitude data from Geolocation Event and passing it along with my required applicationID and gFlags = R for reverse geocoding:

import flash.sensors.Geolocation;
var geolocation:Geolocation;
const YAHOO_URL:String = “”;
const applicationID:String = “GET_YOUR_ID_ON_YAHOO_SITE”;
var loader:URLLoader;

Set the geolocation listener:

if (Geolocation.isSupported) {
geolocation = new Geolocation();
geolocation.addEventListener(GeolocationEvent.UPDATE, onTravel);

Request reverse geolocation data from the Yahoo! service passing the coordinates:

function onTravel(event:GeolocationEvent):void {
var request:URLRequest = new URLRequest(YAHOO_URL);
var variables:URLVariables = new URLVariables();
variables.q = event.latitude.toString() + “n”
+ event.longitude.toString();
variables.gflags = “R”;
variables.appid = applicationID; = variables;
request.method = URLRequestMethod.GET;
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLocationLoaded);
loader.addEventListener(IOErrorEvent.IO_ERROR, onLocationLoaded);
function onError(event:IOErrorEvent):void {
trace(“error”, event);

Parse the XML received from the service to get city and country information:

function onLocationLoaded(event:Event):void {
loader.removeEventListener(Event.COMPLETE, onLocationLoaded);
geolocation.removeEventListener(GeolocationEvent.UPDATE, onTravel);
var xml:XML = new XML(;
var city:String =;
var country:String =;

The XML comes back with a ResultSet.Result node, which includes a street address, city, and country. For example, this is the result for my office building located in New York City’s Times Square:

<name>40.7576303 -73.98716655000001</name>
<line1>230 Rodgers &amp; Hammerstein Row</line1>
<line2>New York, NY 10036-3906</line2>
<line4>United States</line4>
<street>Rodgers &amp; Hammerstein Row</street>
<city>New York</city>
<county>New York County</county>
<state>New York</state>
<country>United States</country>

This address is actually correct for this particular location. It is not my postal address, but it is where I am currently sitting on the west side of the building.

Other interesting data in the XML is woeid and woetype (“woe” is short for Where On Earth). GeoPlanet ( was developed by Yahoo! as a way to identify some features on Earth in a unique, language-neutral manner. This is particularly important because many places in the world have the same name, such as Paris, France, and Paris, Texas.

woeid is a 32-bit unique and nonrepetitive identifier. Numbers follow a hierarchy such as country, state, and city. woetype is the type used to identify a place—in this case, 11 refers to the postal code

Twitter and Flickr are currently using the GeoPlanet system.