Create a scaled circle of maps

Similar questions have been asked here several times here, but none of them seem to give me exactly what I want. I am working with a Bing Map control on a Windows Phone, and I would like to add an ellipse that scales correctly with zoom changes. This can be done using polylines and polygons, but there is no type of ellipse derived from MapShapeBase. I tried different ways to do this, but they need to play with pixel sizes and push the math to match geo-coordinates. I want to create an ellipse with center and dimensions x / y in meters, and everything else. It seems so simple. Did I miss something? My other approach is to draw 365 line segments in poly lines, but that seems awfully ugly, and since the center can move, I will need to snap the location of each segment.It seems very hard. Any other thoughts?

[To be specific, I want to add the GPS Accuracy indicator as a circle around my current location.]

+3
source share
1 answer

Update

In Mango, the phone automatically shows such a circle.

Orginal post

This is pretty easy. You just use the Pushpin control to draw with.

1) Add to your MapLayer control:

<maps:MapLayer>
    <maps:MapPolygon Fill="Gray"
                        IsHitTestVisible="False"
                        Locations="{Binding AccuracyLocationCollection}"
                        Opacity="0.6"
                        Stroke="Black"
                        StrokeThickness="2" />
</maps:MapLayer>

2) Add the AccuracyLocationCollection property to your ViewModel

public LocationCollection AccuracyLocationCollection
{
    get;
    set;
}

3) In the GeoCoordinateWatcher_PositionChanged event handler, calculate the size of the circle and set the value to AccuracyLocationCollection

ViewModel.AccuracyLocationCollection = DrawMapsCircle(e.Position.Location);

4) The DrawMapsCircle code is as follows:

private static double ToRadian (double degree) {degrees of return * (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 , )

Accuracy circle

+5

Source: https://habr.com/ru/post/1782692/


All Articles