Re: Find nearest geographic coordinates
Jesper Louis Andersen <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAGrdgiWjwm+k5YdfF1bi-rn7UnUhLJPhNWZUJgQj0AmBJxO_uQ@mail.gmail.com> |
On Mon, Nov 30, 2020 at 11:05 AM <[email protected]> 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.