Although Google Maps client for Windows Mobile and the Google Maps API have long been available, there have been few samples to use the Google Maps API on a Windows Mobile phone. This is because Google Maps API is available in Javascipt and meant for websites and its terms of service only allow using the API on websites, and not applications.
Getting Google Maps API to work on Windows Mobile
Luckily somebody has done some reverse-engineering on the Google Maps API and made available the observations here. The ideas is that, all Google Maps API functions post their request to http://maps.google.com/maps, and if the request format is known, we can directly call the API from our application using HttpWebRequest class, without having to resort to Json.NET library.
Retrieving your approximate location
The original web page has long gone, but luckily web.archive.org keeps a copy of it. Among the samples, the most interesting one features the ability to get your (approximate) location (e.g. longitude and latitude. a.k.a geocode) from the cells that your mobile phone is currently connected to. Precisely, the application needs to provide the Mobile Country Code (MCC, 525 for Singapore), Mobile Network Code (MNC, 01 for Singtel), Location Area Code (LAC), and Cell-ID and the API will return the approximate geocode.
On a Windows Mobile device, the MCC and the MNC can be retrieved either using lineGetCurrentOperator from Telephony API (TAPI) or RIL_GetCellTowerInfo from Radio Interface Layer (RIL). The other 2 parameters (LAC, CID) can only be retrieved via RIL. Notice that since implementations of TAPI and RIL are OEM-dependent, on some phones you can use both API, on other phones you can use one but not the other and some phones will prohibit access to both APIs.
Getting the address of a location
I improved the sample code further by adding the ability to display the address resolved from geocode. The approach is straightforward by passing the geocode to the following Google URL and passing the response:
where 103 and 2 are the latitude and longitude respectively. The output=json parameter tells Google to return the output in simple text format, which can be read by your code; without it you’ll get a full Google Maps web page.
Getting nearby locations and their addresses
When you use Google Maps’ My Location feature with no GPS, you’ll get a message like “Your location within 300 meteres”. The accuracy (e.g. 300 meters in this case) is calculated automatically based on the cells you are connected to, the neighbouring cells and perhaps the phone signal strength. There is no documented algorithm to calculate this, and the above API also does not return this parameter.
To cater for this, you can get a list of nearby locations within x km of the geocode returned by Google by using the following code snippet to query all the neighbouring geocodes:
double longLatInterval = 0.02;
double longLatDelta = 0.005;
double maxDistance = 1; //get all locations within the specified distance, in km
for (double curLong = lon – longLatDelta; curLong < lon + longLatInterval; curLong += longLatDelta)
for (double curLat = lat – longLatDelta; curLat < lat + longLatInterval; curLat += longLatDelta)
double dist = distance(curLat, curLong, lat, lon, ‘K’);
if (dist < maxDistance)
//found a possible nearby location
where (lon, lat) is your current geocode. You can get the function to calculate the distance between 2 geocodes from here.
The full sample source code can be downloaded here. It is an Windows Mobile 6 console application written in C# that simply displays the addresses of nearby locations and then quits.