Skip to content

GPS to calculate distance between two points on windows phone 7

An answer to this question on Stack Overflow.

Question

i am using GPS to calculate distance between two points i.e. i am using windows phone as a tape measure but when i start i dont get the correct value infact even if i am standing still it gives me hundreds of meter

here is my code

      myWatcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(myWatcher_StatusChanged);
        myWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(myWatcher_PositionChanged);
        myWatcher.MovementThreshold = 1;   
void myWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
    {
        double tempf = e.Position.Location.Latitude;
        double temps = e.Position.Location.Longitude;
        if (count2 == 0)
        {
            FirstLocation = new GeoCoordinate(tempf, temps);
            count2++;
        }
        else
        {
             double distanceInMeter;
            GeoCoordinate currentLocation;
                currentLocation = new GeoCoordinate(tempf, temps);
                distanceInMeter = currentLocation.GetDistanceTo(FirstLocation);                   
                
                if (App.flag == 0)
                {
                    textBlock1.Text = distanceInMeter.ToString() + " m";
                    double distanceInCm = distanceInMeter * 100;
                    textBlock2.Text = distanceInCm .ToString() + " cm";
                }
                else if (App.flag == 1)
                {
                    double distanceInInch = distanceInMeter * 39.3701;
                    textBlock1.Text = distanceInInch.ToString() + " in";
                    double distanceInFoot = distanceInMeter * 3.28084;
                    textBlock2.Text = distanceInFoot.ToString() + " ft";
                }
        }
    }

Answer

The other posters here are generally correct: GPS will not give you the accuracy you need. At least not alone!

Assuming you did have a good satellite fix, you could get an accuracy of centimeters, but this would require post-processing with information from special fixed stations or a live feed of data from such a station. The buzzwords here are "real-time phase differential", "real-time kinematic", "phase-differential post-processing".

This site has some details.

So, if you can get access to feed, it may be possible. But it will not be as easy as you probably hoped.