2015-07-27 3 views
1

Я пытаюсь найти GeoPoint угловWindows Phone 8,1 получить карту в углы GeoPoint

  • TopLeft
  • TopRight
  • BottomLeft
  • BottomRight

Информация, MapControl Предоставляемый

  • центр (GeoPoint)
  • ZoomLevel (Double мин: 1, макс: 20)
  • ActualHeight (Двухместный)
  • ActualWidth (Двухместный)

На основе этой информации можно найти углы?

Я думал, что-то вроде этого:

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

Так что означает, что Center GeoPoint расположен на HalfWdidth (X) и HalfHeight (Y). Может это как-то мне помочь?

Edit: Моя проблема была очень похожа с thisrbrundritt вопрос, как упоминалось, но он дает только TopLeft и BottomRight. Основываясь на принятом ответе на этот вопрос (который был сделан rbrundritt), я также закончил два других и завернул их в Extension, проверьте мой ответ ниже. Спасибо, rbrundritt.

+0

возможно дубликат [Получить вид границы на карте] (http://stackoverflow.com/questions/24468236/get-view-bounds-of-a-map) – rbrundritt

+0

@rbrundritt спасибо за при условии, что link, мне это очень помогло, да, это почти дубликат :) – Almis

ответ

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); 
    } 
}