Sometime you want to create the application that utilizes the latitude and the longitude of the user. What ‘ll be the solution if you are using windows mobile. Well, Microsoft gives information about this. Few days back i switched to windows mobile because client asked me to create location aware application for windows mobile. There are multiple ways to do this
- Retrieving Location Through GPS
- Retrieving Location Through Cell Tower Information
Retrieving Location Through GPS on your Windows Mobile Device
The code to find the latitude and longitude through GPS normally delivers with samples of windows SDK. These are included in windows SDK 5 and 6. You can find those here at this location on your system hard drive
C:\Program Files\Windows Mobile 6 SDK\Samples\PocketPC\CS\GPS
The path may be differed according to the installation path on system. When you ‘ll get that project , open it in a visual studio and build it. Now go to the bin directory and there, you ‘ll see the library with the name Microsoft. WindowsMobile.Samples.Location.dll. To find the latitude and longitude, you ‘ll have to use this dll as reference in your project.
If you are unable to find the project , you can also download it from here
Here is the code to retrieve the latitude and longitude synchronously
InitializeComponent();
gps = new Gps();
gps.Open();
GpsPosition position = gps.GetPosition();
LatLong location = new LatLong();
if (position.LatitudeValid)
location.Latitude = position.Latitude;
if (position.LongitudeValid)
location.Longitude = position.Longitude;
if (position.HeadingValid)
location.Heading = position.Heading;
StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.Append("Latitude = ");
sb.AppendLine(location.Latitude.ToString());
sb.Append("Longitude = ");
sb.AppendLine(location.Longitude.ToString());
sb.Append("Heading = ");
sb.AppendLine(location.Heading.ToString());
label1.Text = sb.ToString();
gps.Close();
Close();
-
Here is the code to find latitude and longitude asynchronously
menuLocationUpdates.Checked = true; gps.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
-
Accessing Cell Tower Information on your Windows Mobile Device
To retrieve cell tower information, you should have knowledge about Radio Interface Layer (RIL) of the device. Microsoft provides the MDD (Model Device Driver ) to access the RIL layer at high level. For this info; you ‘ll have to do the following
- Call the single RIL function
- Call additional function to get additional info
- Close the handle after using RIL functions
Let’s take an example :
You want to get the cell tower information. Now what ‘ll you do
- You ‘ll use RIL_Initialize , to initialize the radio layer interface for use of application .
- Use RIL_GetCellTowerInfo, to retrieve cell tower info.
- Use RIL_Deinitialize, to close and clean up resources.
RILCELLTOWERINFO structure gives you the info about many things. Few of those are:
- Mobile Country Code (MCC)
- Mobile Network Code (MNC)
- Location Area Code (LAC)
- Cell ID (CID)
- Base Station ID
- Broadcast Control Channel (BCCH)
- Received Signal Level (RX Level)
- Received Signal Quality
- Idle Time Slot
- ID of GPRS Cellular Tower
There are many more you can read about the structure of RILCELLTOWERINFO here
Luckily, you are still not able to find latitude and longitude with this info without GPS. You ‘ll have to pass some parameters of RILCELLTOWERINFO to some internet service. Like Yahoo, Google. If you want to use Yahoo or Google service then you ‘ll send this info to any of them
- Cell ID
- Location Area Code
- Mobile Country Code
- Mobile Network Code
In return these services ‘ll return back the latitude and longitude. So one of the most important thing is RIL understanding and usage of Yahoo and Google Service
Code to Access Radio Interface Layer for Information Retrievel
Though you can find the RIL usage on MSDN site but i found the code at this url here on Dale Lane’s blog. For you convenience, i am going to paste the code below
using System;
using System.Threading;
using System.Runtime.InteropServices;
namespace CellId
{
public class RIL
{
// string used to store the CellID string
private static string celltowerinfo = "";
/*
* Uses RIL to get CellID from the phone.
*/
public static string GetCellTowerInfo()
{
// initialise handles
IntPtr hRil = IntPtr.Zero;
IntPtr hRes = IntPtr.Zero;
// initialise result
celltowerinfo = "";
// initialise RIL
hRes = RIL_Initialize(1, // RIL port 1
new RILRESULTCALLBACK(rilResultCallback), // function to call with result
null, // function to call with notify
0, // classes of notification to enable
0, // RIL parameters
out hRil); // RIL handle returned
if (hRes != IntPtr.Zero)
{
return "Failed to initialize RIL";
}
// initialised successfully
// use RIL to get cell tower info with the RIL handle just created
hRes = RIL_GetCellTowerInfo(hRil);
// wait for cell tower info to be returned
waithandle.WaitOne();
// finished - release the RIL handle
RIL_Deinitialize(hRil);
// return the result from GetCellTowerInfo
return celltowerinfo;
}
// event used to notify user function that a response has
// been received from RIL
private static AutoResetEvent waithandle = new AutoResetEvent(false);
public static void rilResultCallback(uint dwCode,
IntPtr hrCmdID,
IntPtr lpData,
uint cbData,
uint dwParam)
{
// create empty structure to store cell tower info in
RILCELLTOWERINFO rilCellTowerInfo = new RILCELLTOWERINFO();
// copy result returned from RIL into structure
Marshal.PtrToStructure(lpData, rilCellTowerInfo);
// get the bits out of the RIL cell tower response that we want
celltowerinfo = rilCellTowerInfo.dwCellID + "-" +
rilCellTowerInfo.dwLocationAreaCode + "-" +
rilCellTowerInfo.dwMobileCountryCode;
// notify caller function that we have a result
waithandle.Set();
}
// -------------------------------------------------------------------
// RIL function definitions
// -------------------------------------------------------------------
/*
* Function definition converted from the definition
* RILRESULTCALLBACK from MSDN:
*
* http://msdn2.microsoft.com/en-us/library/aa920069.aspx
*/
public delegate void RILRESULTCALLBACK(uint dwCode,
IntPtr hrCmdID,
IntPtr lpData,
uint cbData,
uint dwParam);
/*
* Function definition converted from the definition
* RILNOTIFYCALLBACK from MSDN:
*
* http://msdn2.microsoft.com/en-us/library/aa922465.aspx
*/
public delegate void RILNOTIFYCALLBACK(uint dwCode,
IntPtr lpData,
uint cbData,
uint dwParam);
/*
* Class definition converted from the struct definition
* RILCELLTOWERINFO from MSDN:
*
* http://msdn2.microsoft.com/en-us/library/aa921533.aspx
*/
public class RILCELLTOWERINFO
{
public uint cbSize;
public uint dwParams;
public uint dwMobileCountryCode;
public uint dwMobileNetworkCode;
public uint dwLocationAreaCode;
public uint dwCellID;
public uint dwBaseStationID;
public uint dwBroadcastControlChannel;
public uint dwRxLevel;
public uint dwRxLevelFull;
public uint dwRxLevelSub;
public uint dwRxQuality;
public uint dwRxQualityFull;
public uint dwRxQualitySub;
public uint dwIdleTimeSlot;
public uint dwTimingAdvance;
public uint dwGPRSCellID;
public uint dwGPRSBaseStationID;
public uint dwNumBCCH;
}
// -------------------------------------------------------------------
// RIL DLL functions
// -------------------------------------------------------------------
/* Definition from: http://msdn2.microsoft.com/en-us/library/aa919106.aspx */
[DllImport("ril.dll")]
private static extern IntPtr RIL_Initialize(uint dwIndex,
RILRESULTCALLBACK pfnResult,
RILNOTIFYCALLBACK pfnNotify,
uint dwNotificationClasses,
uint dwParam,
out IntPtr lphRil);
/* Definition from: http://msdn2.microsoft.com/en-us/library/aa923065.aspx */
[DllImport("ril.dll")]
private static extern IntPtr RIL_GetCellTowerInfo(IntPtr hRil);
/* Definition from: http://msdn2.microsoft.com/en-us/library/aa919624.aspx */
[DllImport("ril.dll")]
private static extern IntPtr RIL_Deinitialize(IntPtr hRil);
}
}
-
When you ‘ll call the function GetCellTowerInfo() function to retrieve the cell information. You ‘ll get the output string in this format
Cell Id – Location Area Code – Mobile Country Code
e.g 17444 – 5414 – 512 – 423
After getting this, you ‘ll have to pass these parameters either to Fire Eagle Service of Yahoo or to Google Gears API. I ‘ll (inshallah) write more articles on
- Problems with RIL layer
- Problem in getting Mobile Country Code and Mobile Network Code
- Usage of Fire Eagle
- Usage of Google Service
Reference Link
Helping Links
- Getting latitude and longitude without a GPS (Windows Mobile) on stakeoverflow.com
- How to implement Google maps on Windows Mobile on socail.msdn.microsoft.com
- Retrieving Cell ID, MNC, MCC, LAC, IMEI, IMSI in Windows Mobile on socail.msdn.microsoft.com
- How to get the location/cell information of the device? on socail.msdn.microsoft.com
- RILCELLTOWERINFO – Structure & Member Reference on msdn.microsoft.com
- Mobile Network Codes on Wikipedia.com on wikipedia.com
- Programmatically getting the CellID from your Windows Mobile phone on dalelane.co.uk







My partner and I really enjoyed reading this blog post, I was just itching to know do you trade featured posts? I am always trying to find someone to make trades with and merely thought I would ask.
Most of the blogs online are pretty much the same but i think that your blog can be an exception. Grats !
I’ve recently started a blog, the information you provide on this site has helped me tremendously. Thank you for all of your time & work.
Pretty nice post. I just stumbled upon your blog and wanted to say that I have really enjoyed browsing your blog posts. In any case I’ll be subscribing to your feed and I hope you write again soon!
Hey all
can any one advise me?
I need a zero cost MMORPG who has a number of players and they (well the majority of) can talk English. It’s vital that the particular servers have a very great number of gamers. I am hunting for something such as Diablo and Wow. I’m furthermore not willing to pay money as I have some time to kill at this moment. It can be okay if the actual game is provided for free along with premium content. I’ve looked a lot regarding MMORPGs but not one of the web sites definitely say just how much players tend to be online.
cheers
Sorry … no idea …