Xamarin Forms - Map.Loaded event handlers not called on iOS (but it is on Android)

430
1
04-09-2019 07:03 AM
Highlighted
New Contributor III

Hello,

We've got an interesting problem. In the OnAppearing of on of our views that has a Map, we've wired up the Map.Loaded event and for some reason the event handler is not getting called on iOS - it is getting called on Android, but not on iOS.

Any ideas? The code is pretty straight forward...

        protected override void OnAppearing()
        {
            base.OnAppearing();
            EsriMap.Map.Loaded += Map_Loaded;
        }
        private void Map_Loaded(object sender, EventArgs e)
        {
            EsriMap.LocationDisplay.IsEnabled = true;
        }

Thanks,

Mike Hamsa

Reply
0 Kudos
1 Reply
Highlighted
Esri Frequent Contributor

Did you check the Map wasn't already loaded before hooking up the event handler?

There are also ways to create a map that's loaded from the beginning (ie no information needed to be loaded to start rendering) and in that case it won't fire the event, so it's always good practice to check the LoadStatus up front.

Another thing you could do is just force-load the map (if it's already loaded it's a no-op). Ie:

        protected async override void OnAppearing()
        {
            base.OnAppearing();
            await EsriMap.Map.LoadAsync(); //TODO: You should try/catch this, as a load failure would throw here
            EsriMap.LocationDisplay.IsEnabled = true;
        }
Reply
0 Kudos