1

I trying to find the Geopoint of corners

  • TopLeft
  • TopRight
  • BottomLeft
  • BottomRight

The information that MapControl provides is

  • Center (Geopoint)
  • ZoomLevel (Double min:1, max:20)
  • ActualHeight (Double)
  • ActualWidth (Double)

Based on that information can I find the corners?

I was thinking something like that:

double HalfHeight = Map.ActualHeight / 2;
double HalfWidth = Map.ActualWidth / 2;

So that means that Center Geopoint is located on HalfWdidth (X) and HalfHeight (Y). Can somehow this help me?

Edit: My problem was very similar with this question as rbrundritt mentioned but it was giving only TopLeft and BottomRight. Based on the accepted answer of that question (which is by rbrundritt) I also completed the other two and wrapped them in Extension, check my answer below. Thank you rbrundritt.

Community
  • 1
  • 1
Almis
  • 3,684
  • 2
  • 28
  • 58
  • possible duplicate of [Get view bounds of a Map](http://stackoverflow.com/questions/24468236/get-view-bounds-of-a-map) – rbrundritt Jul 28 '15 at 16:19
  • @rbrundritt thank you for providing that link, it helped me a lot and yeah it's almost duplicate :) – Almis Jul 28 '15 at 18:02

1 Answers1

0
public static class MapExtensions
{
    private static Geopoint GetCorner(this MapControl Map, double x, double y, bool top)
    {
        Geopoint corner = null;

        try
        {
            Map.GetLocationFromOffset(new Point(x, y), out corner);
        }
        catch
        {
            Geopoint position = new Geopoint(new BasicGeoposition()
            {
                Latitude = top ? 85 : -85,
                Longitude = 0
            });

            Point point;
            Map.GetOffsetFromLocation(position, out point);
            Map.GetLocationFromOffset(new Point(0, point.Y), out corner);
        }

        return corner;
    }

    public static Geopoint GetTopLeftCorner(this MapControl Map)
    {
        return Map.GetCorner(0, 0, true);
    }

    public static Geopoint GetBottomLeftCorner(this MapControl Map)
    {
        return Map.GetCorner(0, Map.ActualHeight, false);
    }

    public static Geopoint GetTopRightCorner(this MapControl Map)
    {
        return Map.GetCorner(Map.ActualWidth, 0, true);
    }

    public static Geopoint GetBottomRightCorner(this MapControl Map)
    {
        return Map.GetCorner(Map.ActualWidth, Map.ActualHeight, false);
    }
}
Almis
  • 3,684
  • 2
  • 28
  • 58