Obtaining the CellID of a device is only part of the story. CellIDs are nothing more than strings of numbers; they are useful only when you have a way to translate these numbers into latitude and longitude information. That's where Google Maps comes in handy.
If you have ever used Google Maps for Mobile, you should be familiar with the My Location feature. This feature allows you to show your current location on the map, even if you don’t have GPS on the device. How does Google Maps do this? The trick lies in the use of the CellID obtained by Google Maps on your device. Once the CellID is obtained, it is sent back to a secret API at Google Maps at www.google.com/glm/mmap, which will then return the latitude and longitude to which the CellID corresponds. Apparently, Google Maps has a huge database containing all the world's CellIDs (at least it worked pretty well for me in Singapore).
Some really intelligent folks actually analyzed the packets returned by Google Maps and write some C# code that allows you to pass in a CellID to Google Maps to obtain the latitude and longitude of a location. One of them is Neil Young, who published his C# code here.
In this article, you'll modify that code and package it into a class. Add a new Windows Forms application project to the current solution and name it GoogleMaps. Add a new Class item to the project and name it GMM.cs. Populate the class as follows shown in Listing 3.
Basically, the GMM class contains a static method called GetLatLng(), that accepts an array parameter containing Mobile Country Code (MCC), Mobile Network Code (MNC), Location Area Code (LAC), and CellID (CID). The GetLatLng() method returns the latitude and longitude separated by a "|" character, like this:
Once the geographical location of a CellID is obtained, you want to display the location using Google Maps. Because Google Maps is hosted within a web browser, you will use a WebBrowser
control to contain it.
First, populate the default Form1 with the controls shown in Figure 3.
|Figure 3. Form1: Populating the default Form1.|
When the user clicks the Load Cell IDs button, load the log file containing the CellIDs and display them in the ListBox control:
private void btnLoadCellIDs_Click(object sender, EventArgs e)
OpenFileDialog openFileDialog1 = new OpenFileDialog()
Filter = "Text files (*.txt)|*.txt"
if (openFileDialog1.ShowDialog() == DialogResult.OK)
System.IO.StreamReader sr =
string strCellIDs = sr.ReadToEnd();
string cellIDs = strCellIDs.Split('\n');
foreach (string str in cellIDs)
lstCellIDs.Items.Add(str.Replace('\r', ' '));
When the user selects a CellID in the ListBox
control, extract the CellID from the ListBox
control, and send the appropriate parameters into the GetLatLng()
static method. When the latitude and longitude information is returned, set the WebBrowser
control to navigate to the Google Maps application by feeding the latitude and longitude information in the query string (see Listing 4
That's it! You can now test the application by setting the GoogleMaps project as the startup project and then pressing F5. Perform the following steps to test the application:
|Figure 4. Location! Displaying the location for the particular CellID.|
- Capture a series of CellIDs by running the LBS project created in the first part of this article. The beauty of using CellIDs is that it works in-door as well. In fact, so long as you have a phone signal, you can obtain the CellID. A good way to capture CellIDs is to leave it in your car as you drive. You will be able to pick up a good series of different CellIDs.
- Copy the CellIDs.txt log file from your Windows Mobile device onto your computer.
- In the GoogleMaps application, click on the Load Cell IDs button to load the CellIDs.txt file. Once this is done, you should see the list of CellIDs and the time each CellID was taken displayed in the ListBox control.
- Click on each CellID and the WebBrowser control will automatically display the location for the particular CellID (see Figure 4)!
Use the techniques in this article, to make your own exciting, location-based service applications!