Friday, June 20, 2008

After the last GPS related application, GPS Compass, I’ve been wanting to do another GPS focused application. This time I figured we’d get in the driver’s seat with our friend: SPEED.

Gentlemen, start your engines…

image

Mobile Speedometer

The application is built off of  Windows Mobile 6 SDK included a GPS Application in the samples folder, C:\Program Files\Windows Mobile 6 SDK\Samples\PocketPC\CS\GPS.

This uses the GPS Intermediate Driver. If you are writing a location aware application for Windows Mobile this is definitely the way to go. ;)

The main UI is located at the top of the screen. We have a simple speedometer graphic in the background to add some flair to the application. On top of this we overlay the current speed based off of information returned from the GPS device. We can also use Fake GPS to simulate a GPS device.

Below this we have a readout of various GPS statistics that are updated continuously.

One thing to note is Speed may be return in knots which you will likely want to convert to either miles or kilometers.

 

 

 

 

We just need to create a method something like UpdateData below.

   1: void UpdateData(object sender, System.EventArgs args)
   2: {
   3:     if (gps.Opened)
   4:     {
   5:         if (position != null)
   6:         {
   7:             if (position.SpeedValid)
   8:             {
   9:                 labelSpeed.Text = (position.Speed/1.15077945).ToString("0.00");
  10:             }
  11:          }
  12:      }
  13: }

Possibilities:

I think a more realistic UI would be a great improvement. And the ability to switch from miles to kilometers would be good too. If the odometer would track miles traveled that would be an awesome enhancement.

Download executable: mobileSpeedometer.cab

Download Source Code: mobileSpeedometer.zip

Feedback:

Want more? What else would you like to see?


Friday, June 20, 2008 07:09:36 (Eastern Standard Time, UTC-05:00)
Hello Chris.

I'm from Argentina and I read this page daily. It's very interesting.

Ideas for the next few days.
Create an RSS reader.
Create an application display animated GIF.
how to get data that is configured proxy.
Create an application using sqlce.
Create an application using Merge Replication.
An program manager in memory.(to front,close,minimize)

I congratulate you because what you do is very interesting

Greetings

PD:Excuse me but I don't know write in English
D1eg0
Friday, June 20, 2008 09:37:58 (Eastern Standard Time, UTC-05:00)
Hi,

I would like to suggest the code below to calculate the distance between two Gps Positions.

This calculates a distance between two gps positions as the crow flies. I have added it to my own GPS Sample which includes a call to CalculateDistanceAsMiles in the UpdateData method. This method uses a class level variable called previousPosition and then passes both previousPosition and position to the method.

// Calculates the distance between the previousPosition and the current Position
if (previousPosition == null)
{
previousPosition = position;
}

if (previousPosition != null)
{
DistanceCalculator.DistanceTravelledInMiles += DistanceCalculator.CalculateDistanceAsMiles(previousPosition, position);
}

previousPosition = position;

// Distance Calculator class which calculates the distance in either Miles or KM between two positions.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.WindowsMobile.Samples.Location;

namespace GpsSample
{
/// <summary>
/// Allows the calculation of a distance given two sets of co-ordinates
/// The equation was taken from http://www.movable-type.co.uk/scripts/latlong.html
/// This is an 'as the crow flies' calculation
/// </summary>
public class DistanceCalculator
{
#region Internal Member Variables

private static double _distanceTravelledInKm = 0;
private static double _distanceTravelledInMiles = 0;

#endregion

#region Constructor

public DistanceCalculator()
{
}

#endregion

#region Methods

public static double CalculateDistanceAsKm(GpsPosition previousPostion, GpsPosition currentPosition)
{
int R = 6371; // km
double lat1 = previousPostion.Latitude;
double lat2 = currentPosition.Latitude;
double long1 = previousPostion.Longitude;
double long2 = currentPosition.Longitude;

double dLat = (Math.PI * (lat2 - lat1)) / 180;
double dLon = (Math.PI * (long2 - long1)) / 180;
double lat1rad = (Math.PI * (lat1)) / 180;
double lat2rad = (Math.PI * (lat2)) / 180;

double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
Math.Cos(lat1rad) * Math.Cos(lat2rad) *
Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
double d = R * c;

return d;
}

public static double CalculateDistanceAsMiles(GpsPosition previousPostion, GpsPosition currentPosition)
{
double miles = CalculateDistanceAsKm(previousPostion, currentPosition) / 1.609344d;

return miles;
}

#endregion

#region Properties

public static double DistanceTravelledInKm
{
get
{
return _distanceTravelledInKm;
}
set
{
_distanceTravelledInKm = value;
}
}

public static double DistanceTravelledInMiles
{
get
{
return _distanceTravelledInMiles;
}
set
{
_distanceTravelledInMiles = value;
}
}

#endregion
}
}
Paul Diston
Comments are closed.

Theme design by Jelle Druyts

Pick a theme: