Esri Runtime LocationDisplay in Xamarin Forms Apps

02-18-2019 12:24 PM
Occasional Contributor


Initially this may be more of a confirmation that LocationDisplay works in a Xamarin Forms App. Right now I'm doing some testing in our app and when I set IsEnabled to true, I get a StatusChanged event notification, but IsStarted is set to false. It looks like IsEnabled is then set back to false as well, as if it didn't start.

Reading the API reference, it says that if IsEnabled gets set back to false, there was an error starting the location display and you can use StartAsync on the DataSource if you need more error information because StartAsync returns an error. I couldn't find any error information returned from this method so I tried wrapping a call to StartAsync in a try/catch, and it does catch an exception, but the exception message is "One or more errors occurred". I cannot see any additional details about the errors.

Code wise: Right now, I've added a new event handler for the Map.Loaded event. In my Map_Loaded event handled, I'm starting the LocationDisplay. For Android (where I'm currently testing), I've got the FINE, COARSE, and MOCK location permissions set as required.

Here's my Map_Loaded method - it is really pretty basic, and it gets called after the map loads.

private void Map_Loaded(object sender, EventArgs e)
   //EsriMap.LocationDisplay.ShowLocation = true;
   //EsriMap.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Off;
   EsriMap.LocationDisplay.IsEnabled = true;

Does LocationDisplay work in Xamarin Forms app?

If so, what is the best approach to getting this to work?

I really just want it to turn on as soon as the map loads up.


Mike Hamsa

0 Kudos
1 Reply
Occasional Contributor


Just wanted to clear this up in case anyone else has the same question. I was able to get this working after correctly requesting app permissions. Starting with Android 6.0 you have to request app permissions a little differently and once we got that wired up in the Xamarin Forms app, LocationDisplay started working as expected.

If you are having problems starting LocationDisplay I'd suggest using StartSync on the DataSource because it does return more useful error information, I just missed it the first time around.


0 Kudos