1
我想找到距離我的位置4000km的地方的GeoCoordinate,將其命名爲newLocation
。將距離轉換爲WP8中的GeoCoordinate
我需要,爲了結果轉化爲ViewportPoint
這樣的:
System.Windows.Point p1 =
mapControl.ConvertGeoCoordinateToViewportPoint(newLocation);
,並假設我的位置被定義爲:
System.Windows.Point p2 =
radiusMap.ConvertGeoCoordinateToViewportPoint(myLocation);
那麼我可以簡單地添加中心的圓我的位置和邊界通過newLocation
,我需要計算,如下所示:
double radius = getDistance(p1, p2);
Ellipse circle = new Ellipse();
circle.Width = radius * 2;
circle.Height = radius * 2;
circle.Opacity = 0.4;
circle.Fill = new SolidColorBrush(Colors.Green);
MapOverlay mapOverLay = new MapOverlay();
mapOverLay.PositionOrigin = new System.Windows.Point(0.5, 0.5);
mapOverLay.Content = circle;
mapOverLay.GeoCoordinate = myLocation;
MyLayer.Add(mapOverLay);
radiusMap.Layers.Add(MyLayer);
所以,計算newLocation
是我所需要的。
注:
- 我試圖this solution但有一個限制。
我們可以在Visual Studio中的以下內容:
GeoCoordinate location1 = ..., location2 = ...; double distance = location1.GetDistanceTo(location2);
不知逆已經實現。
更新:我發現GetDistanceTo(...)的實施,那就是:
double d = this.Latitude * 0.017453292519943295;
double num3 = this.Longitude * 0.017453292519943295;
double num4 = other.Latitude * 0.017453292519943295;
double num5 = other.Longitude * 0.017453292519943295;
double num6 = num5 - num3;
double num7 = num4 - d;
double num8 = Math.Pow(Math.Sin(num7/2.0), 2.0) + ((Math.Cos(d) * Math.Cos(num4)) * Math.Pow(Math.Sin(num6/2.0), 2.0));
double num9 = 2.0 * Math.Atan2(Math.Sqrt(num8), Math.Sqrt(1.0 - num8));
return (6376500.0 * num9);
我不知道如果讓反是可以或不可以。即給予我的地理座標和離我的距離,以便返回新位置的地理座標。
感謝您的回答。我會測試這些方程並給你反饋。 – 2013-02-18 14:03:12