Last active
April 16, 2018 11:20
-
-
Save icebeam7/39f2f96138d57afa12c84fbc1a7a223c to your computer and use it in GitHub Desktop.
Hora Local: ServicioGelocalizacion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ejemplo adaptado de la documentación: https://jamesmontemagno.github.io/GeolocatorPlugin/CurrentLocation.html | |
using Plugin.Geolocator; | |
using Plugin.Geolocator.Abstractions; | |
using System; | |
using System.Threading.Tasks; | |
namespace HoraLocal.Servicios | |
{ | |
public static class ServicioGelocalizacion | |
{ | |
public static async Task<Position> ObtenerUbicacionActual() | |
{ | |
Position ubicacion = null; | |
try | |
{ | |
var gps = CrossGeolocator.Current; | |
gps.DesiredAccuracy = 100; | |
if (!gps.IsGeolocationAvailable || !gps.IsGeolocationEnabled) | |
return null; | |
ubicacion = await gps.GetPositionAsync(TimeSpan.FromSeconds(20), null, true); | |
} | |
catch (Exception ex) { } | |
if (ubicacion == null) | |
return null; | |
return ubicacion; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment