Click here to Skip to main content
15,880,796 members
Articles / Programming Languages / C#

Global Positioning Device Software

, ,
Rate me:
Please Sign up or sign in to vote.
4.84/5 (16 votes)
9 Dec 2012CPOL2 min read 47.5K   4.4K   53   11
A C# based application to trace the location of a GPS device.

Introduction

We needed to develop an application which could plot the position of a device placed in a vehicle or a container etc., for a given interval of time and date, over map in a C# .NET based software.

Background

We are doing Industrial Electronics Engineering form IIEE, Karachi, Pakistan. The idea of this project came when we visited an electronic project exhibition where we saw a project displaying the latitude and longitude on an LCD using a GPS module. This inspired us to build a portable/wireless device which can log its GPS coordinates using a cell phone attached to it. We started working on that but as our exams came near our respected Sir Sajid Hussain gave us a project to develop a software using C#. This is where our project really got its shape. We decided to merge our C# project with the GPS project to make a software which can detect and plot the position of our GPS device. Sir Sajid Hussain gave us the idea of including a GSM module in it for updating the position of our device on a web server from where our software gets the data and plot it on the map. The software is customizable for multiple devices.  

Image 1

The Code

The code of this project can be divided into three parts.

  1. GMAP.NET.
  2. HTTP Web Request (System.NET).
  3. XCoolForms for Windows (Additional Feature).

GMAP.NET 

The code uses GMap.NET.dll and GMap.NET.WindowsForms.dll to add controls to the XCoolForms, and it is quite easy and simple to use. First of all, GMapControls need to be initialized using:

C#
gMapControl1.SetCurrentPositionByKeywords("Pakistan"); // The country to be focused after map is loaded
gMapControl1.gMapProvider = GMapProviders.GoogleMap;// The map provider
gMapControl1.MapScaleInfoEnabled = true;
gMapControl1.ForceDoubleBuffer = true;
gMapControl1.RoutesEnabled = true;// Map can have Routes
gMapControl1.MinZoom = 2;     // Minimum zoom level
gMapControl1.MaxZoom = 26;    // Maximum zoom level
gMapControl1.Zoom = 10;       // Initial zoom level
gMapControl1.DragButton = MouseButtons.Left;// Mouse button used for dragging the map

Placing a Marker on the Map

C#
GMapOverlay myOverlay1 = new GMapOverlay(gMapControl1,"myOverlay1"); //Constructing object for Overlay
myOverlay1.Markers.Add(new gMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(
   new PointLatLng(latitude,longitude)));//Adding a new Marker in the Overlay 
gMapControl1.Overlays.Add(myOverlay1);// Adding myOverlay1 to the Control

Fetching the Data from the Server

The following request will return data from the server stored by a GPS device and save it as a string.

C#
WebRequest request = WebRequest.Create("http://www.Abc......");// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;// Get the response.
WebResponse response = request.GetResponse();// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);// Read the content. 
string responseFromServer = reader.ReadLine();// Display the content. 

Plotting Route on the Map

C#
GMapOverlay routes = new GMapOverlay(gMapControl1, "routes");// Constructing object for Overlay
gMapControl1.Overlays.Add(routes);
List<PointLatLng> list = new List<PointLatLng>(); // The list of Coordinates to be plotted
list.Add(new PointLatLng(32.710525233333,51.709773683333));
list.Add(new PointLatLng(32.711725983333,51.704725066667)); 
.
.
.
.
list.Add(new PointLatLng(32.713785566667,51.66982365));
GMapRoute r = new GMapRoute(list, "myroute"); // object for routing
r.Stroke.Width = 5;
r.Stroke.Color = Color.Red;
routes.Routes.Add(r);
gMapControl1.ZoomAndCenterRoute(r);
gMapControl1.Zoom = 15;

ToolTip 

To display related information of pointers, we need to add tooltip functionality to it. It can be added using these code segments:

C#
GMapOverlay myOverlay1 = new GMapOverlay(gMapControl1, "myOverlay1");   
GMapMarkerGoogleGreen CurrentMarker;
CurrentMarker = new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(new PointLatLng(latitude, longitude));
CurrentMarker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
CurrentMarker.ToolTipText = "Your Text Here!";
myOverlay1.Markers.Add(CurrentMarker);
gMapControl1.Overlays.Add(myOverlay1);

Additional features

XCoolForms

Although it’s not necessary, we wanted to add a little color to our dull looking form, so we decided to add XCoolForms for the windows in our project, which we got from http://www.codeproject.com/Articles/33716/Fancy-Windows-Forms. This is not a major part of our project and we just wanted to add some colors, the code and explanation for this feature can be found in the given link.

Custom Markers

As an additional feature we also added custom markers in our map like red dot, blue dot, and arrow. For this purpose we obtained a custom marker class from http://www.codeproject.com/Articles/32643/GMap-NET-Great-Maps-for-Windows-Forms-and-Presenta.

Point of Interest 

The device we made will work anywhere as long as the signal strength from the GSM vendor remains. 

Image 2

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Instructor / Trainer Institute of Industrial Electronics Engineering
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionLicence Pin
C_McLeod14-Oct-13 4:57
C_McLeod14-Oct-13 4:57 
GeneralGood one Pin
Master.Man198010-Dec-12 5:36
Master.Man198010-Dec-12 5:36 
SuggestionThe complete link of this project work Pin
Umair Mukati10-Dec-12 2:49
Umair Mukati10-Dec-12 2:49 
QuestionBrilliant work Pin
Shayan Ali Bhatti8-Dec-12 1:02
Shayan Ali Bhatti8-Dec-12 1:02 
QuestionMy vote of 5 Pin
cassio.scherer6-Dec-12 1:02
professionalcassio.scherer6-Dec-12 1:02 
GeneralMy vote of 5 Pin
rix_gem5-Dec-12 4:19
rix_gem5-Dec-12 4:19 
QuestionWhere To Get Device Pin
Yash Parikh5-Dec-12 0:26
Yash Parikh5-Dec-12 0:26 
GeneralMy vote of 5 Pin
Programm3r4-Dec-12 21:14
Programm3r4-Dec-12 21:14 
QuestionNice article Pin
Sean Botha4-Dec-12 18:46
Sean Botha4-Dec-12 18:46 
GeneralBrillient Effort Pin
Mac William4-Dec-12 6:41
Mac William4-Dec-12 6:41 
QuestionSource code Pin
Smitha Nishant4-Dec-12 6:31
protectorSmitha Nishant4-Dec-12 6:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.