none
Problem with using TrySetViewBoundsAsync for MapControl in UWP RRS feed

  • Question

  • Hi

    I'm building an UWP app, using the MapControl. I have two BasicGeoposition, as mentioned as the following code, one set to obviously NorthWest position and the other is SouthEast.

    When I try to use TrySetViewBoundsAsync, the map didn't have any response. I checked the property for the GeoboundingBox, it does calculated the center point of the map, the map just don't "zoom in".

            protected override async void OnNavigatedTo(NavigationEventArgs e)
            {
                BasicGeoposition nw = new BasicGeoposition() { Latitude = 5.0000, Longitude = 0.0, Altitude = 0 };
                BasicGeoposition se = new BasicGeoposition() { Latitude = 0.0000, Longitude = 10.0, Altitude = 0 };
    
                GeoboundingBox bound = new GeoboundingBox(nw, se);
                await MyMap.TrySetViewBoundsAsync(bound, null, Windows.UI.Xaml.Controls.Maps.MapAnimationKind.Bow);
            }


    And if I manually set the following code

    MyMap.Center = new Geopoint(bound.Center);

    the map will move to the center, this proved that the GeobondingBox is correctly set.

    Any ideas what's wrong with it? Or did I miss out anything?


    Snake Chia http://www.nearby.com.my

    Tuesday, May 31, 2016 1:54 PM

Answers

  • Hi Shaw Chyn,

    Changing map's view bounds in OnNavigatedTo event handler does not work indeed. I think it is because the map is not loaded at that time.

    It should work if you use MapControl's LoadingStatusChanged event in some way like:

    MapControl.LoadingStatusChanged += async (m, o)=>
                {
                     if (m.LoadingStatus == MapLoadingStatus.Loaded)
                     {
                         BasicGeoposition nw = new BasicGeoposition() { Latitude = 5.0000, Longitude = 0.0, Altitude = 0 };
                         BasicGeoposition se = new BasicGeoposition() { Latitude = 0.0000, Longitude = 10.0, Altitude = 0 };
    
                         GeoboundingBox bound = new GeoboundingBox(nw, se);
                         await m.TrySetViewBoundsAsync(bound, null, MapAnimationKind.Bow);
                     }
                };

    Put this code into your OnNavigated event handler. And it would work.

    You can notice the time delay after the map is loaded and moved to the specified bounds.

    Monday, February 20, 2017 12:32 PM