Find nearest geographic coordinates

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Fri Dec 4 16:13:43 CET 2020


On Mon, Nov 30, 2020 at 11:05 AM <empro2@REDACTED> wrote:

> ```
> Ls = [{geoloc, 6.1457, 46.2022},
>       {geoloc, 2.3387, 48.8582},
>       ...],
> Lc = [{geocart, X, Y, Z}, ...].
>
> %% Perhaps with something like:
> -record(geoloc, {longitude :: float(),
>                  latitude :: float()}).
> ```
>

>From experience, I usually recommend you use naming when handling multiple
fields of the same type. I.e., the record is probably the best solution.
Otherwise, switching up lat/lng is simply too easy. It also happens with
lots of other data. In languages with types you would do something like

module GeoLoc = struct
  type t = { lat : float; lng : float }
  let from_pair ~lat ~lng = { lat; lng }
  let distance x y = ... (* This will have type t -> t -> float *)
end

So in order to create a GeoLoc.t you call `from_pair ~lng:6.1457
~lat:46.2022`. You can then make GeoLoc.t abstract such that you can't
access the internal representation outside the module, protecting against a
large number of mistakes as the system develops.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20201204/041d1fe7/attachment.htm>


More information about the erlang-questions mailing list