Latitude and Longitude Special Characters in Erlang/Mnesia

398 views Asked by At

Trying to wrangle some special characters in Erlang (the shell for now), particularly degrees, minutes, and seconds as used in latitude/longitude.

I've read all about the unicode module and experimented with the x_to_y functions and cant seem to get I°J′K″ N X°Y′Z″ W to appear appropriately in the shell. One thing to note is I extract these values from an HTTP request, store them in an Mnesia database, and will want to send them back in a response.

I don't really care if I get them to look pretty in the shell, as long as I can make sense of them later, in different contexts (e.g. a web page).

The question boils down to: how do I know that Erlang is receiving the correct characters, and is there a way I can confirm that the list of integers will reconstruct into the proper form later?

While I do need to achieve the above, would the general recommendation would be to convert the coordinates to decimals and store them that way?

1

There are 1 answers

0
Pascal On BEST ANSWER

An efficient way to store such values is to use a tuple {D,M,S}, if you have to reuse the value it will avoid unexpected rounding issues. A decimal value is worth if you only have to make calculations with the the information.

It is possible to check that you got the right value using the pretty print format "~p" to directly print the tuple. Note that, when it is possible, it is better to use pattern matching for test than rely on the shell output. The shell is really good for fast evaluation, but it introduces some diffences compare to the execution in modules (usage of pretty print by default, no real variable assignment, different handling of anonymous functions specially when exchanged between nodes...)