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.
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 of this project can be divided into three parts.
- HTTP Web Request (System.NET).
- XCoolForms for Windows (Additional Feature).
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.gMapProvider = GMapProviders.GoogleMap;
gMapControl1.MapScaleInfoEnabled = true;
gMapControl1.ForceDoubleBuffer = true;
gMapControl1.RoutesEnabled = true;
gMapControl1.MinZoom = 2;
gMapControl1.MaxZoom = 26;
gMapControl1.Zoom = 10;
gMapControl1.DragButton = MouseButtons.Left;
Placing a Marker on the Map
GMapOverlay myOverlay1 = new GMapOverlay(gMapControl1,"myOverlay1");
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......");
request.Credentials = CredentialCache.DefaultCredentials;
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadLine();
Plotting Route on the Map
GMapOverlay routes = new GMapOverlay(gMapControl1, "routes");
List<PointLatLng> list = new List<PointLatLng>();
GMapRoute r = new GMapRoute(list, "myroute");
r.Stroke.Width = 5;
r.Stroke.Color = Color.Red;
gMapControl1.Zoom = 15;
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");
CurrentMarker = new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(new PointLatLng(latitude, longitude));
CurrentMarker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
CurrentMarker.ToolTipText = "Your Text Here!";
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.
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
Point of Interest
The device we made will work anywhere as long as the signal strength from the GSM vendor remains.