我正在使用 GPS 来计算两点之间的距离,即我使用 windows phone 作为卷尺但是当我开始时我没有得到正确的值事实上即使我站着不动它给了我数百米
这是我的代码
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";
}
}
}