Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Last active April 16, 2018 13:04
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/e8a91959af76a79fea655d910bf754c7 to your computer and use it in GitHub Desktop.
Save icebeam7/e8a91959af76a79fea655d910bf754c7 to your computer and use it in GitHub Desktop.
Hora Local: PaginaHoraLocal.xaml.cs
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