Skip to content Skip to sidebar Skip to footer

Xamarin, Using Geolocation From Xlabs Sample

Using Xamarin Shared Project. I tryed to include in my share project the Geolocation feature from Xlabs sample but i'm having problems when it comes to call the dependencyService.

Solution 1:

XLabs.Platform services are no longer (since update to 2.0) automatically registered with Xamarin.Forms.DependencyService. This is due to removal of Xamarin.Forms dependency on XLabs.Platform. You can either register the Geolocator manually (from each platform specific project):

 DependencyService.Register<Geolocator> ();

Better option would be to use the IoC container abstraction provided by XLabs.IoC (included automatically as dependency): https://github.com/XLabs/Xamarin-Forms-Labs/wiki/IOC

More on XLabs.IoC: http://www.codenutz.com/autofac-ninject-tinyioc-unity-with-xamarin-forms-labs-xlabs/

Solution 2:

The second parameter of Command Constructor is a function that tell if the command can be executed or not, in your case you are "telling" to only execute the command when Geolocator is != null, but you are initializing it in your command, which is never executed because Geolocator is null.

You should initialize the Geolocator before the command is called or remove the Geolocator is != null condition to execute the command.

Post a Comment for "Xamarin, Using Geolocation From Xlabs Sample"