<div dir="auto">Thanks for your help guys. </div><div dir="auto"><br></div><div dir="auto">/Frank</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Mon 30 nov. 2020 Â 04:07, Anders Dahlin <<a href="mailto:anders@dahlinenergy.se">anders@dahlinenergy.se</a>> wrote :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">I don't know how well this will suite your needs, but it's what I use to<br>
calculate the distance between to {Lat, Lng} points.<br>
<br>
-define(EarthRadius, 6372.8).<br>
<br>
haversine({Lat1, Lng1}, {Lat2, Lng2}) -><br>
  Â  RLat1 = deg2rad(Lat1),<br>
  Â  RLat2 = deg2rad(Lat2),<br>
  Â  DLat  = RLat2 - RLat1,<br>
  Â  DLng  = deg2rad(Lng2) - deg2rad(Lng1),<br>
  Â  A  Â  Â = math:pow(math:sin(DLat/2), 2) +<br>
  Â  Â  Â  Â  Â  math:pow(math:sin(DLng/2), 2) * math:cos(RLat1) * math:cos(RLat2),<br>
  Â  C  Â  Â = 2 * math:asin(math:sqrt(A)),<br>
  Â  ?EarthRadius * C.<br>
<br>
deg2rad(Deg) -><br>
  Â  math:pi() * Deg / 180.<br>
<br>
<br>
On 2020-11-28 20:09, Joa Gre wrote:<br>
> This might come in handy:<br>
> <br>
> %% <a href="https://en.m.wikipedia.org/wiki/Geographic_coordinate_conversion#From_geodetic_to_ECEF_coordinates" rel="noreferrer" target="_blank">https://en.m.wikipedia.org/wiki/Geographic_coordinate_conversion#From_geodetic_to_ECEF_coordinates</a> <<a href="https://en.m.wikipedia.org/wiki/Geographic_coordinate_conversion#From_geodetic_to_ECEF_coordinates" rel="noreferrer" target="_blank">https://en.m.wikipedia.org/wiki/Geographic_coordinate_conversion#From_geodetic_to_ECEF_coordinates</a>> <br>
> %% <a href="https://en.m.wikipedia.org/wiki/Geodetic_datum#World_Geodetic_System_1984_(WGS_84)" rel="noreferrer" target="_blank">https://en.m.wikipedia.org/wiki/Geodetic_datum#World_Geodetic_System_1984_(WGS_84)</a> <<a href="https://en.m.wikipedia.org/wiki/Geodetic_datum#World_Geodetic_System_1984_(WGS_84)" rel="noreferrer" target="_blank">https://en.m.wikipedia.org/wiki/Geodetic_datum#World_Geodetic_System_1984_(WGS_84)</a>><br>
> <br>
> geodetic_to_ecef_coordinates(Latitude, Longitude, H) -><br>
>  Â  Â CLatitude = math:cos(Latitude * ?RADIANS_PER_DEGREE),<br>
>  Â  Â SLatitude = math:sin(Latitude *  ?RADIANS_PER_DEGREE),<br>
>  Â  Â CLongitude = math:cos(Longitude * ?RADIANS_PER_DEGREE),<br>
>  Â  Â SLongitude = math:sin(Longitude  * ?RADIANS_PER_DEGREE),<br>
>  Â  Â %% Semi-major axis<br>
>  Â  Â A = 6378137.0,<br>
>  Â  Â A2 = math:pow(A, 2),<br>
>  Â  Â %% Semi-minor axis<br>
>  Â  Â B = 6356752.3142,<br>
>  Â  Â B2 = math:pow(B, 2),<br>
>  Â  Â %% Prime vertical radius of curvature<br>
>  Â  Â N = A2 / math:sqrt(<br>
>  Â  Â  Â  Â  Â  Â  Â  math:pow(CLatitude, 2) * A2 + math:pow(SLatitude, 2) * B2),<br>
>  Â  Â X = (N + H) * CLatitude * CLongitude, <br>
>  Â  Â Y = (N + H) * CLatitude * SLongitude, <br>
>  Â  Â Z  = (B2 / A2 * N + H) * SLatitude,<br>
>  Â  Â {X, Y, Z}.<br>
> <br>
> <br>
> Den ons 25 nov. 2020 22:39Frank Muller <<a href="mailto:frank.muller.erl@gmail.com" target="_blank">frank.muller.erl@gmail.com</a><br>
> <mailto:<a href="mailto:frank.muller.erl@gmail.com" target="_blank">frank.muller.erl@gmail.com</a>>> skrev:<br>
> <br>
>  Â  Â Hi guys,<br>
> <br>
>  Â  Â I've a list of geographic coordinates: <br>
> <br>
>  Â  Â L = [ {{<<"longitude">>,6.1457}, {<<"latitude">>,46.2022}},<br>
>  Â  Â Â  Â  Â  {{<<"longitude">>,2.3387}, {<<"latitude">>,48.8582}},<br>
>  Â  Â Â  Â  Â  ... ]<br>
> <br>
>  Â  Â and a specific coordinate X = {{<<"longitude">>,-73.5848},<br>
>  Â  Â {<<"latitude">>,45.4995}}.<br>
> <br>
>  Â  Â Question: how can i find the nearest coordinates to X from L (sorted<br>
>  Â  Â from the nearest to the farest)?<br>
> <br>
>  Â  Â /Frank<br>
> <br>
</blockquote></div></div>