Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Take Your Apps Far and Wide with a GPS Tracking System  : Page 4

You already know that GPS is used extensively in a wide variety of mobile devices in order to track delivery and service vehicles—or any other mobile fleet. This kind of application is not as difficult as you may at first think. Find out how to use Visual Studio to create a GPS tracking app, with maps, that runs on Windows Mobile Pocket PC devices.

Modifying the Pocket PC Application
Back in the Pocket PC (GPSTracking) project, add a new Class item to the project and name it as Sync.vb. Populate the class with the following:

Imports System.Net Imports System.Net.Sockets Public Class Sync Const portNo As Integer = 3456 Dim client As Socket Public Sub PerformSync( _ ByVal HostIP As String, _ ByVal txtData As String) Try Dim RemoteAdd As System.Net.IPAddress = _ System.Net.IPAddress.Parse(HostIP) Dim endPoint As New IPEndPoint(RemoteAdd, portNo) client = New Socket(endPoint.AddressFamily, _ SocketType.Stream, ProtocolType.Tcp) client.Connect(endPoint) '---send a message to the server Dim data As Byte() = _ System.Text.Encoding.ASCII.GetBytes(txtData) '---send the text--- client.Send(data) client.Close() Catch ex As Exception MsgBox(ex.ToString) End Try End Sub End Class

The purpose of this class is to open a socket connection to the server and send the ID of the user, as well as latitude and longitude information, to it.

In Form1.vb, declare and instantiate the Sync class so that you can connect to the server:

Figure 9. Testing the entire system and tracking two different users.

Public Class Form1 '---use for synchronization--- Dim sync As New Sync

Modify the processGPSData() subroutine so that after displaying the latitude and longitude information on the screen, you will send the data to the server:

Private Sub processGPSData(ByVal str As String) Dim rawLatLng As Double Try ... ... '---display the lat and lng--- lblLat.Text = "Lat:" & lat lblLng.Text = "Lng:" & lng '---synchronize with the server--- sync.PerformSync(ServerIP, ID & ":" & lat & ":" & ... ... End Sub

That's it! You can now test the entire system. With the server running, run the Pocket PC application and click the Connect GPS menu item. By default, the ID of the Pocket PC application is set to "1", and hence the left map on the server (see Figure 9) will display the location for user "1". If you set the ID of the Pocket PC application to "2", the right map will be updated instead. Hence, the system in this article allows two Pocket PCs to be traced at the same time (of course, you can scale it up to monitor multiple users).

Wei-Meng Lee is a Microsoft MVP and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies. He is an established developer and trainer specializing in .NET and wireless technologies. Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies. He writes extensively on topics ranging from .NET to Mac OS X. He is also the author of the .NET Compact Framework Pocket Guide, ASP.NET 2.0: A Developer's Notebook (both from O'Reilly Media, Inc.), and Programming Sudoku (Apress). Here is Wei-Meng's blog.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.