private async Task MoveToSantaAna() { try { var request = new GeolocationRequest(GeolocationAccuracy.Medium); System.Threading.CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); var location = await Geolocation.GetLocationAsync(request, cts.Token); if (location != null) { await MainThread.GetMainThreadSynchronizationContextAsync(); //Trae de vuelta el MainThread Mapa.MoveToRegion( MapSpan.FromCenterAndRadius( new Position( location.Latitude, location.Longitude ), Distance.FromMeters(3000) )); } } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception Crashes.TrackError(fnsEx, new Dictionary <string, string>() { { "Mapa", "FeatureNotSupportedException" } }); } catch (FeatureNotEnabledException fneEx) { // Handle not enabled on device exception if (Device.RuntimePlatform == Device.Android) { DependencyService.Get <IGPSService>().turnOnGps(); } Crashes.TrackError(fneEx, new Dictionary <string, string>() { { "Mapa", "FeatureNotEnabledException" } }); } catch (PermissionException pEx) { // Handle permission exception Crashes.TrackError(pEx, new Dictionary <string, string>() { { "Mapa", "PermissionException" } }); } catch (Exception ex) { // Unable to get location Crashes.TrackError(ex, new Dictionary <string, string>() { { "Mapa", "Exception" } }); } }
static XamarinWrapper() { Utility.WriteDebugEntryMessage(System.Reflection.MethodBase.GetCurrentMethod()); MainThreadSynchronizationContext = MainThread.GetMainThreadSynchronizationContextAsync().Result; }
public Task <SynchronizationContext> GetMainThreadSynchronizationContextAsync() { return(MainThread.GetMainThreadSynchronizationContextAsync()); }