GPS’s are popular systems in the tech world and Microsoft has provided a GPS API for windows mobile developers. This article will show how to find a location, a driving route and more using windows mobile. It will have two parts; the first part will talk about configuration and basic idea about GPS and account creation with Microsoft map point service. The second one talks about code and test with real map point service and more.

Introduction:

GPS’s are very common in the tech world along with most of the applications or systems related with them.   To meet this demand, Microsoft released a GPS access developer tool kit for the .Net compact framework. SO here I’m going to talk about how we can get a place map within a windows mobile device.  For our example we want to go from Washington to Seattle by car.

Prerequisites:

1. Windows Mobile 6 SDK
2. Windows Mobile 5/6 Professional Emulator.
3. The GPS basic knowledge’s
4. Active Sync 4.5 (to vista Windows mobile Device Center)
5. Visual Studio 2008

Overview:

Most of the popular mobile manufacturers are making specific devices for GPS use only. In the future GPS systems will become even more highly demanded; therefore developers must understand how to work with GPS systems.

The Global Positioning System (GPS) is a satellite-based navigation system made up of a network of 24 satellites placed into orbit by the U.S. Department of Defense. GPS was originally intended for military applications, but in the 1980s, the government made the system available for civilian use. GPS works in any weather conditions, anywhere in the world, 24 hours a day. There are no subscription fees or setup charges to use GPS.

If you want to know more about GPS history, visit http://en.wikipedia.org/wiki/Global_Positioning_System.

Microsoft has released a collection of class library for GPS access. You can check out the class library class design here.    

Now we will look a simple GUI design for our demo.



This is a very simple GUI for GPS demonstration. Here I’m going to display basic Global position system information.

Implementation:

First I’m going to address references and access the GPS locations. Then I’m going to write using a statement like the one below.



Then you can create a GPS object to access the GPS methods and properties. From the GUI I have three buttons: firstly one to start the GPS, secondly one is to stop the GPS and the final one is to cancel the currently running application. Then you want to write a few lines of code for the start button.



Initially I created a GPS object when I initliazed the form in the sample project,  now I’m going to use that object to get gps information.  If you view my button click code, I  first check if the GPS is opened, if the GPS is opened, I  close the GPS and unregister the events.

If not opened I’m going to open the GPS and register .


Now we will look at what we want to implement under those two events.  The first event Device states the Changed event, so why does the event need to be registered and raised?

The GPS device position has several states.


Then I’m going implement the devicestatechanged event as followings:


Now we need to update the information GUI, but we can’t do that directly because of the GPS call in the external background thread. So when we try to update the GUI by the external thread, it will go through the cross thread exception.  For more about cross thread GUI update visit http://www.liensberger.it/web/blog/?p=90.

So you need to create a delegate object to update control with your internal method.


Let’s move to another event called location changed. You may  wonder why you a need location changed event.  The GPS uses locations so if you want to get the latest position from the satelite you need to access the location changed event within your code.

    When you access the device State event you can only learn about device state but if you need position information you should access location change event. That must be done as followings:


This code snippet is the same as the previous code, but a little different.  Here we are accessing position instead of the DeviceState, before we were updating control based on the Latitude & Longitude.

That’s all from coding side, build the application and run it.  Before running the application we want to setup the testing enviroment in the windows mobile emulator because we don’t have direct access  to GPS in the windows mobile emulator.  I ‘m going to talk about environment setup and some more about GPS, in the next part of this article.

You can download the sample project there and also in this article.

[Download Sample]

About the Author:  

My name is RRaveen, currently living and working in Singapore. Ii am highly focusing on to provide better Solutions to business problems which are commonly an organization facing, retrieve information on time using information technologies.Since i loves windows mobile technology design and implementation business applications which is based on C#.And my other specializations are Asp.net,WPF and WCF .
i have been working on many back ends which are Mysql,Sqlserver and Oracle/PL/SQL/TOAD hands on experience more than 3 and a half year.