<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>