0
我正在開發一個小型Windows Phone應用程序。我將用戶的當前位置存儲在數據庫中。Windows Phone 7 GetDistanceTo()返回不正確的距離
這是檢索存儲在數據庫中的當前位置的代碼。
public void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
CurrentLatitude = e.Position.Location.Latitude.ToString();
CurrentLongitude = e.Position.Location.Longitude.ToString();
}
我們需要允許用戶做一些活動,如果他在距離他保存的位置400米以下。
我使用下面的代碼來計算距離。
internal double GetDistanceTo(GeoCoordinate ClientLocation)
{
double distanceInMeter;
GeoCoordinate currentLocation = new GeoCoordinate(Convert.ToDouble(watcher.Position.Location.Latitude.ToString()), Convert.ToDouble(watcher.Position.Location.Longitude.ToString()));
distanceInMeter = currentLocation.GetDistanceTo(ClientLocation);
return distanceInMeter;
}
ClientLocation:是保存在數據庫中的位置。
所以我的問題是,即使用戶站在相同的位置(1米以下),它保存在數據庫中,它給了極大的距離。
(從設備中提取)實施例cordinates
在數據庫保存
緯度:29.8752546310425
長:73.8865985870361
電流Cordinates
緯度:29.8734102249146
長:73.9049253463745距離 1780.45
可能有人建議我這裏有什麼問題或者更好的辦法讓兩個座標之間的距離?
GeoCoordinateWatcher公開MovementThreshold屬性。此屬性指定在引發PositionChanged事件之前必須發生的最小位置變化。在我的情況下,移動閾值設置爲10.0f米,現在我設置爲1.0f米,這樣我就可以獲得有關最小位置變化的正確數據,從而解決了我的問題。 – Sam 2012-04-17 10:46:32