Hi,
I'm stuck with an error when using Xamarin.Geolocation (component : Xamarin.Mobile) for the iOS project.
I used the code sample provided with the component here . It worked perfectly for Android. But for iOS, I got this error (translated from french to english) :
'Xamarin.Geolocation.Geolocator' does not contain a constructor that takes 0 arguments
I looked for the definition of Geolocator and found this :
public class Geolocator
{
public Geolocator(Android.Content.Context context);
...
}
Indeed, the constructor expect one argument. But the code sample tells us to use App.Geolocator = new Geolocator { DesiredAccuracy = 50 }; for iOS
And, obviously, I cannot use an Android context in an iOS app... Does someone know how to deal with that ?
Here is the rest of the code if needed :
In Shared (App.cs) :
public static Geolocator Geolocator;
...
async void GetPosition()
{
await Geolocator.GetPositionAsync(10000).ContinueWith(t =>
{
if (t.IsFaulted || t.IsCanceled)
MainPage.DisplayAlert("Location", "Couldn't determine location", "Ok");
else
lat = t.Result.Latitude;
lon = t.Result.Longitude;
MainPage.DisplayAlert("Location", string.Format("Latitude: {0}\nLongitude: {1}",
t.Result.Latitude, t.Result.Longitude), "Ok");
}, TaskScheduler.FromCurrentSynchronizationContext());
}
In Android (MainActivity.cs) :
protected override void OnCreate (Bundle bundle)
{
...
App.Geolocator = new Geolocator(this) { DesiredAccuracy = 50 };
...
}
In iOS (AppDelegate.cs) :
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
...
App.Geolocator = new Geolocator { DesiredAccuracy = 50 };
...
}
Thnaks for help