You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Justice.Helpers
|
|
|
|
|
{
|
|
|
|
|
public class GeolocationHelper
|
|
|
|
|
{
|
|
|
|
|
public static async Task<(double Latitude, double Longitude)> GetCurrentLocationAsync()
|
|
|
|
|
{
|
|
|
|
|
var location = await Geolocation.Default.GetLocationAsync();
|
|
|
|
|
if (location != null)
|
|
|
|
|
{
|
|
|
|
|
return (location.Latitude, location.Longitude);
|
|
|
|
|
}
|
|
|
|
|
throw new Exception("Unable to fetch location");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<string> GetReadableAddressAsync(double latitude, double longitude)
|
|
|
|
|
{
|
|
|
|
|
var placemarks = await Geocoding.Default.GetPlacemarksAsync(latitude, longitude);
|
|
|
|
|
var placemark = placemarks.FirstOrDefault();
|
|
|
|
|
if ( placemark !=null)
|
|
|
|
|
{
|
|
|
|
|
return $"{placemark.SubLocality}, {placemark.Thoroughfare}, {placemark.Locality}, {placemark.CountryName}";
|
|
|
|
|
}
|
|
|
|
|
return "Address Not Found";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|