创建缩放的地图圆

Ari*_*ulp 3 math bing-maps windows-phone

这里曾经多次询问过类似的问题,但它们似乎都没有给我我想要的东西.我正在使用Windows Phone上的Bing Map控件,我想添加一个椭圆,可以根据缩放更改进行正确缩放.这可以使用多边形线和多边形来完成,但是没有从MapShapeBase派生的椭圆类型.我已经尝试了各种方法,但它们需要使用像素大小并捏造数学以使其与地理坐标对齐.我想创建一个椭圆,其中心和x/y尺寸以米为单位,其余部分由框架完成.看起来很简单.我错过了某个地方吗?我的另一种方法是在折线中绘制365个线段,但这看起来非常难看,而且由于中心可以移动,我需要绑定每个线段的位置.这看起来非常重.还有其他想法吗?

[具体来说,我想在当前位置周围添加一个"GPS准确度"指示器.]

Cla*_*sen 5

更新

在芒果,手机会自动显示这样一个圆圈.

原始邮报

这很容易.您只需使用图钉控件进行绘图.

1)将MapLayer添加到您的控件:

<maps:MapLayer>
    <maps:MapPolygon Fill="Gray"
                        IsHitTestVisible="False"
                        Locations="{Binding AccuracyLocationCollection}"
                        Opacity="0.6"
                        Stroke="Black"
                        StrokeThickness="2" />
</maps:MapLayer>
Run Code Online (Sandbox Code Playgroud)

2)在ViewModel中添加AccuracyLocationCollection属性

public LocationCollection AccuracyLocationCollection
{
    get;
    set;
}
Run Code Online (Sandbox Code Playgroud)

3)在GeoCoordinateWatcher_PositionChanged事件处理程序中,计算圆的大小,并将值设置为AccuracyLocationCollection

ViewModel.AccuracyLocationCollection = DrawMapsCircle(e.Position.Location);
Run Code Online (Sandbox Code Playgroud)

4)DrawMapsCircle的代码如下:

private static double ToRadian(double degrees){return degrees*(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;
}
Run Code Online (Sandbox Code Playgroud)

结果:(这是我家附近,我可以确认,灰色圆圈之间的道路之间约有3米)

准确性圈