更新
在 Mango 中,手机会自动显示这样一个圆圈。
原帖
这很容易。您只需使用图钉控件进行绘图。
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(double degree) { return degree * (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米)