アップデート
マンゴーでは、電話は自動的にそのような円を表示します。
元の投稿
かなり簡単です。画鋲コントロールを使用して描画を行うだけです。
1)MapLayerをコントロールに追加します。
<maps:MapLayer>
<maps:MapPolygon Fill="Gray"
IsHitTestVisible="False"
Locations="{Binding AccuracyLocationCollection}"
Opacity="0.6"
Stroke="Black"
StrokeThickness="2" />
</maps:MapLayer>
2)ViewModelにAccuracyLocationCollectionプロパティを追加します
public LocationCollection AccuracyLocationCollection
{
get;
set;
}
3)GeoCoordinateWatcher_PositionChangedイベントハンドラーで、円のサイズを計算し、値をAccuracyLocationCollectionに設定します
ViewModel.AccuracyLocationCollection = DrawMapsCircle(e.Position.Location);
4)DrawMapsCircleのコードは次のようになります。
private static double ToRadian(doubledegrees){returndegrees *(Math.PI / 180); }
private static double ToDegrees(double radians)
{
return radians * (180 / Math.PI);
}
public static LocationCollection DrawMapsCircle(GeoCoordinate location)
{
double earthRadiusInMeters = 6367.0 * 1000.0;
var lat = ToRadian(location.Latitude);
var lng = ToRadian(location.Longitude);
var d = location.HorizontalAccuracy / earthRadiusInMeters;
var locations = new LocationCollection();
for (var x = 0; x <= 360; x++)
{
var brng = ToRadian(x);
var latRadians = Math.Asin(Math.Sin(lat) * Math.Cos(d) + Math.Cos(lat) * Math.Sin(d) * Math.Cos(brng));
var lngRadians = lng + Math.Atan2(Math.Sin(brng) * Math.Sin(d) * Math.Cos(lat), Math.Cos(d) - Math.Sin(lat) * Math.Sin(latRadians));
locations.Add(new Location()
{
Latitude = ToDegrees(latRadians),
Longitude = ToDegrees(lngRadians)
});
}
return locations;
}
結果:(これは私の家の隣にあり、灰色の円が表示されている道路の間に約3メートルあることを確認できます)
