Last active
April 16, 2018 13:04
-
-
Save icebeam7/e8a91959af76a79fea655d910bf754c7 to your computer and use it in GitHub Desktop.
Hora Local: PaginaHoraLocal.xaml.cs
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
using System; | |
using Xamarin.Forms; | |
using Xamarin.Forms.Xaml; | |
using HoraLocal.Servicios; | |
namespace HoraLocal.Paginas | |
{ | |
[XamlCompilation(XamlCompilationOptions.Compile)] | |
public partial class PaginaHoraLocal : ContentPage | |
{ | |
public PaginaHoraLocal () | |
{ | |
InitializeComponent (); | |
} | |
void Loading(bool mostrar) | |
{ | |
indicator.IsEnabled = mostrar; | |
indicator.IsRunning = mostrar; | |
} | |
public async void btnObtenerUbicacion_Clicked(object sender, EventArgs e) | |
{ | |
Loading(true); | |
var ubicacion = await ServicioGelocalizacion.ObtenerUbicacionActual(); | |
if (ubicacion != null) | |
{ | |
txtLatitud.Text = ubicacion.Latitude.ToString(); | |
txtLongitud.Text = ubicacion.Longitude.ToString(); | |
} | |
else | |
{ | |
await DisplayAlert("Advertencia", "La ubicación no se pudo obtener", "OK"); | |
} | |
Loading(false); | |
} | |
public async void btnObtenerHoraUbicacion_Clicked(object sender, EventArgs e) | |
{ | |
Loading(true); | |
double latitud, longitud; | |
if (double.TryParse(txtLatitud.Text, out latitud) | |
&& double.TryParse(txtLongitud.Text, out longitud)) | |
{ | |
var fechaActual = await ServicioTimeZone.ObtenerHoraLocal(latitud, longitud, ServicioTimeZone.token); | |
if (fechaActual != null) | |
{ | |
lblFechaActual.Text = String.Format("{0:dd-MMMM-yyyy hh:mm:ss tt}", fechaActual.Value); | |
} | |
else | |
{ | |
await DisplayAlert("Advertencia", "Debes introducir coordenadas geográficas válidas", "OK"); | |
} | |
} | |
else | |
{ | |
await DisplayAlert("Advertencia", "Debes introducir coordenadas geográficas válidas", "OK"); | |
} | |
Loading(false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment