using Plugin.Geolocator.Abstractions;
public static class CommonExtensions
public static double ToRadian(this double value)
return (Math.PI / 180) * value;
public struct GeoCoordinates : ICloneable
public bool IsEmpty { get { return Longitude.Equals(0) && Latitude.Equals(0); } }
public string Text { get { return ToString(); } }
return new GeoCoordinates()
public new string ToString()
return Latitude + "," + Longitude;
public static void Main()
GeoCoordinates login = new GeoCoordinates() {
Longitude = -73.937688833
GeoCoordinates login2 = new GeoCoordinates() {
GeoCoordinates site = new GeoCoordinates() {
double result = GetDistanceInMiles(site,login);
double resultEAPI = GetDistanceInMilesEAPI(site,login);
Console.Write("Mobile: " + result);
Console.Write("EAPI: " + resultEAPI);
public static double GetDistanceInMilesEAPI(GeoCoordinates geoCoordinatesX, GeoCoordinates geoCoordinatesY) {
Double aSq = Math.Pow(geoCoordinatesX.Latitude - geoCoordinatesY.Latitude, 2);
Double bSq = Math.Pow(geoCoordinatesX.Longitude - geoCoordinatesY.Longitude, 2);
Double milesBetween = Math.Sqrt(cSq) * 69.2;
public static double GetDistanceInMiles(GeoCoordinates geoCoordinatesX, GeoCoordinates geoCoordinatesY)
double deltaLatitude = (geoCoordinatesY.Latitude - geoCoordinatesX.Latitude).ToRadian();
double deltaLongitude = (geoCoordinatesY.Longitude - geoCoordinatesX.Longitude).ToRadian();
Math.Sin(deltaLatitude / 2) *
Math.Sin(deltaLatitude / 2) +
Math.Cos(geoCoordinatesX.Latitude.ToRadian()) *
Math.Cos(geoCoordinatesY.Latitude.ToRadian()) *
Math.Sin(deltaLongitude / 2) *
Math.Sin(deltaLongitude / 2);
return 3960 * (2 * Math.Asin(Math.Min(1, Math.Sqrt(a))));