Question

I want draw the offline circle over the geocoordinate in windows phone this circle is of 1500 meter range and it search the target within this range

enter image description here this my image where i have point to draw circle using width and heigth but i want to draw circle using radius while i zoom, the range of the circle also affected

and also search the target within this range or not

    //  double metersPerPixels = (Math.Cos(geo.Latitude * Math.PI / 180) * 2 * Math.PI * 6378137) / (256 * Math.Pow(2, map.ZoomLevel));
    // double radius = 1000 / metersPerPixels;



    map.Layers.Add(new MapLayer()
          {
            new MapOverlay()
            {
                GeoCoordinate = geo,                   
                PositionOrigin = new Point(0.5,0.5),   
                 Content = new Ellipse
                {   

                    Opacity=.4,
                    Fill = new SolidColorBrush(color),
                    Width = 100,//radius * 2 
                    Height =100 //adius * 2 

                }
             }                
          });
Was it helpful?

Solution

Here you go, you can use it with your own class by changing the Location class in this helper.

Here is the sample helper to create a circle out of the initializing point and radius in meter:

/// <summary>
/// The geo drawing helper.
/// </summary>
public class GeoDrawingHelper
{
    #region Constants

    /// <summary>
    /// The c_ earth radius in kilometers.
    /// </summary>
    public const double c_EarthRadiusInKilometers = 6367.0;

    #endregion

    #region Public Methods and Operators

    /// <summary>
    /// Creates a circle by the initializing point.
    /// </summary>
    /// <param name="center">
    /// The center Point.
    /// </param>
    /// <param name="radius">
    /// The radius in meter.
    /// </param>
    /// <returns>
    /// The <see cref="List"/>.
    /// </returns>
    public static List<Location> CreateCirclePoints(Location center, double radius)
    {
        double lat = ToRadian(center.Latitude); // radians
        double lng = ToRadian(center.Longitude); // radians
        double d = radius / (c_EarthRadiusInKilometers * 1000); // d = angular distance covered on earth's surface
        var locations = new List<Location>();

        for (var x = 0; x <= 360; x++)
        {
            // Calculate the coordinates of the point
            double brng = ToRadian(x);
            double latRadians = Math.Asin((Math.Sin(lat) * Math.Cos(d)) + (Math.Cos(lat) * Math.Sin(d) * Math.Cos(brng)));
            double lngRadians = lng
                                + Math.Atan2(
                                    Math.Sin(brng) * Math.Sin(d) * Math.Cos(lat), 
                                    Math.Cos(d) - (Math.Sin(lat) * Math.Sin(latRadians)));

            // Add the location
            locations.Add(new Location() { Latitude = ToDegrees(latRadians), Longitude = ToDegrees(lngRadians) });
        }

        return locations;
    }

    /// <summary>
    /// Convert the radian to degrees measure.
    /// </summary>
    /// <param name="radians">
    /// The radians.
    /// </param>
    /// <returns>
    /// The <see cref="double"/>.
    /// </returns>
    public static double ToDegrees(double radians)
    {
        return radians * (180 / Math.PI);
    }

    /// <summary>
    /// Convert the degrees to radian measure.
    /// </summary>
    /// <param name="degrees">
    /// The degrees.
    /// </param>
    /// <returns>
    /// The <see cref="double"/>.
    /// </returns>
    public static double ToRadian(double degrees)
    {
        return degrees * (Math.PI / 180);
    }

    #endregion
}

OTHER TIPS

To prevent elipses on sertain latitudes I use the following code:

// Function to draw circle on map:

private void DrawCircle(BasicGeoposition CenterPosition, int Radius)
    {
    Color FillColor = Colors.Purple;
    Color StrokeColor = Colors.Red;
    FillColor.A = 80;
    StrokeColor.A = 80;
    Circle = new MapPolygon
        {
            StrokeThickness = 2,
            FillColor = FillColor,
            StrokeColor = StrokeColor,
            Path = new Geopath(Functions.CalculateCircle(CenterPosition, Radius))
        };
    mpBingMaps.MapElements.Add(Circle);
}

// Constants and helper functions:

const double earthRadius = 6371000D;
const double Circumference = 2D * Math.PI * earthRadius;

public static List<BasicGeoposition> CalculateCircle(BasicGeoposition Position, double Radius)
{
    List<BasicGeoposition> GeoPositions = new List<BasicGeoposition>();
    for (int i = 0; i <= 360; i++)
    {
        double Bearing = ToRad(i);
        double CircumferenceLatitudeCorrected = 2D * Math.PI * Math.Cos(ToRad(Position.Latitude)) * earthRadius;
        double lat1 = Circumference / 360D * Position.Latitude;
        double lon1 = CircumferenceLatitudeCorrected / 360D * Position.Longitude;
        double lat2 = lat1 + Math.Sin(Bearing) * Radius;
        double lon2 = lon1 + Math.Cos(Bearing) * Radius;
        BasicGeoposition NewBasicPosition = new BasicGeoposition();
        NewBasicPosition.Latitude = lat2 / (Circumference / 360D);
        NewBasicPosition.Longitude = lon2 / (CircumferenceLatitudeCorrected / 360D);
        GeoPositions.Add(NewBasicPosition);
    }
    return GeoPositions;
}

private static double ToRad(double degrees)
{
    return degrees * (Math.PI / 180D);
}

This code is usefull for small radius of less than a few miles.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top