Click here to Skip to main content
Click here to Skip to main content

Global Positioning Device Software

, , , 9 Dec 2012
Rate this:
Please Sign up or sign in to vote.
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.  

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:

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

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.

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

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:

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. 

License

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

Share

About the Authors

sajidhussainbaloch
Instructor / Trainer Institute of Industrial Electronics Engineering
Pakistan Pakistan
No Biography provided

Umair Mukati

Pakistan Pakistan
No Biography provided

Naveed Ahmed

Pakistan Pakistan
No Biography provided

Comments and Discussions

 
QuestionLicence PinmemberC_McLeod14-Oct-13 4:57 
GeneralGood one PinmemberMaster.Man198010-Dec-12 5:36 
SuggestionThe complete link of this project work PinmemberUmair Mukati10-Dec-12 2:49 
QuestionBrilliant work PinmemberShayan Ali Bhatti8-Dec-12 1:02 
QuestionMy vote of 5 Pinmembercassio.scherer6-Dec-12 1:02 
GeneralMy vote of 5 Pinmemberrix_gem5-Dec-12 4:19 
QuestionWhere To Get Device Pinmemberyash09245-Dec-12 0:26 
GeneralMy vote of 5 PinmemberProgramm3r4-Dec-12 21:14 
QuestionNice article PinmemberSean Botha4-Dec-12 18:46 
GeneralBrillient Effort PinmemberMac William4-Dec-12 6:41 
QuestionSource code PinstaffSmitha Vijayan4-Dec-12 6:31 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 10 Dec 2012
Article Copyright 2012 by sajidhussainbaloch, Umair Mukati, Naveed Ahmed
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid