Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Last active April 16, 2018 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icebeam7/39f2f96138d57afa12c84fbc1a7a223c to your computer and use it in GitHub Desktop.
Save icebeam7/39f2f96138d57afa12c84fbc1a7a223c to your computer and use it in GitHub Desktop.
Hora Local: ServicioGelocalizacion
// 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