none
Obtaining the horizontal and vertical distances of the map at the current zoom level RRS feed

  • Question

  • I have a UWP app and I allow the user to zoom in and out.

    I want to do a spatial query and I know the centre point of the map but I can't seem to find a way to obtain the current map distances shown in the horizontal and vertical.

    Is there a way to obtain these distances ?

    TIA

    db 

    Wednesday, June 6, 2018 10:40 AM

Answers

  • I have found a way by getting the coordinate of one of the corners and along with the centre point I can calculate the distances; I used...

        {MapControlName}.GetLocationFromOffset(new Point(mapControlAif.ActualWidth, 0), out Geopoint northEast);

    Does anyone know of a better way?

    • Marked as answer by db_cad Wednesday, June 6, 2018 5:11 PM
    Wednesday, June 6, 2018 3:41 PM

All replies

  • I have found a way by getting the coordinate of one of the corners and along with the centre point I can calculate the distances; I used...

        {MapControlName}.GetLocationFromOffset(new Point(mapControlAif.ActualWidth, 0), out Geopoint northEast);

    Does anyone know of a better way?

    • Marked as answer by db_cad Wednesday, June 6, 2018 5:11 PM
    Wednesday, June 6, 2018 3:41 PM
  • For getting the visible region to use in a spatial query, the best API to use is GetVisible Region

    https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.maps.mapcontrol.getvisibleregion

    Specifically, you probably want to use MapVisibleRegionKind.Near to avoid getting weird results when in oblique/rotated views. If you use GetLocationFromOffset as above, you'll have to deal with cases where the map control corners don't intersect the ground (zoomed out in globe view or looking obliquely towards the horizon).

    GetVisibleRegion with MapVisibleRegionKind.Near should always give you a sensible polygon to use for a spatial search.

    Wednesday, June 6, 2018 4:30 PM
    Moderator
  • Sorry, I should have said more about my spatial query. It's a query to another site (URL) so I can only use a centre point and radius. Hence a polygon spatial query does not help me here but thanks for pointing out the getvisibleregion as I will probably need that when I switch the data over to Cosmos DB.

    Thanks again.

    Wednesday, June 6, 2018 5:10 PM
  • You should be able to calculate a radius from the polygon returned by GetVisibleRegion. It will still be more reliable than querying the corner of the map control. Just pick the polygon point that's farthest from the center (or nearest depending on how conservative you want the search to be).
    Wednesday, June 6, 2018 5:59 PM
    Moderator
  • Thanks, I will try the GetVisibleRegion as I do expect the user view from oblique and rotated views (i.e. not looking down the Z axis).
    Thursday, June 7, 2018 2:59 PM