How do I get a reference to SystemLocationDataSource in .net Standard Library?

989
3
06-08-2020 09:16 AM
JayBowman
New Contributor II

I have an .net Xamarin Map app that I created using a .net Standard class library for all my shared code, Xamarin forms. How do i get a reference to a SystemLocationDataSouce that is only available in the android or IOS project.

0 Kudos
3 Replies
JoeHershman
MVP Regular Contributor

Not 100% sure what you mean bu get a reference to...

SystemLocationDataSource is a device dependent implementation of LocationDataSource, so having the class available in the .net shared Xamarin library is not be possible.

However, in my shared project the property mapView.LocationDisplay.DataSource will be the SystemLocationDataSource for the currently running platform

Thanks,
-Joe
0 Kudos
dotMorten_esri
Esri Notable Contributor

We should make that easier I agree. Currently that API is only available for platform-specific code, and not part of the .NET Standard API surface.

For now you can do what I did here:

arcgis-toolkit-dotnet/ContinuousGPSSample.xaml.cs at master · Esri/arcgis-toolkit-dotnet · GitHub 

This should return a value when running on Xamarin.iOS, Xamarin.Forms, UWP, .NET Core and .NET Framework (even if you compiled for .NET Standard).

0 Kudos
dotMorten_esri
Esri Notable Contributor

FYI once update 9 ships, from a .NET Standard library you'll be able to call: LocationDataSource.CreateDefault() to get a location-datasource for the platform. Until then you can use the code snippet I linked to above.

0 Kudos