PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → GPS Coordinates
GPS Coordinates
Iniciado por guest, 13,mar. 2016 12:05 - 3 respuestas
Publicado el 13,marzo 2016 - 12:05
Hi All

I am just entering the GPS coordinate data storage and programming. I know nothing about it. I have a few questions:

1. What is the best data type when storing the longitude and latitude?

2. If it is a number such as a real are there functions to convert this from the number to a string to present it in human readable form and from that back to the number?

I know nothing about this so excuse the stupidity of the question.

Cheers
André
Publicado el 14,marzo 2016 - 12:22
Hello André,

there are several ways to represent GPS coordinate, either as a numeric or as a string. How YOU do it depends of where you getting the values from (and therefore in which format) and/or how you are going to use them.

Best regards
Publicado el 14,marzo 2016 - 19:06
My suggestion is for you to store the coordinates in decimal degree format.

For example, Paris coordinates are 48° 52' N, 2° 19' 58" E, then you transform this degree minutes seconds format in decimal degree by the formula: ((sec / 60) + min) / 60 + degree. Conventionalizing that for latitude north is positive and south is negative and for longitude east is positive and west is negative, then you would have the point (48.87, 2.33).
For Manaus (where I live) the coordinates are 3° 6' 0" S, 60° 01' 0" W = (-3.1, -60.02).

An interesting exercise is to calculate the distance between 2 points. I have it in TypeScript (adapted from: http://stackoverflow.com/questions/365826/calculate-distance-between-2-gps-coordinates), will leave it to you as an exercise to code it in WL, in the case you want.

static terrestrialDistance(latitude1 : number, longitude1 : number, latitude2 : number, longitude2 : number) : number { const earthEquatorialRadius : number = 6378.1370; // in Km // converting the coordinates from decimal degrees to radians latitude1 = latitude1 * Math.PI / 180; longitude1 = longitude1 * Math.PI / 180; latitude2 = latitude2 * Math.PI / 180; longitude2 = longitude2 * Math.PI / 180; // pre calculation const differenceLatitudes : number = latitude2-latitude1; const differenceLongitudes : number = longitude2-longitude1; const n : number = Math.sin(differenceLatitudes / 2) * Math.sin(differenceLatitudes / 2) + Math.sin(differenceLongitudes / 2) * Math.sin(differenceLongitudes / 2) * Math.cos(latitude1) * Math.cos(latitude2); // finally, calculating the distance return 2 * Math.atan2(Math.sqrt(n), Math.sqrt(1 - n)) * earthEquatorialRadius; }
The result is in Kilometres. For miles, divide by 1.60934.

To calculate the distance between Paris and Manaus:
Paris coordinates: 48° 52' N, 2° 19' 58" E = (48.87, 2.33)
Manaus coordinates: 3° 6' 0" S, 60° 01' 0" W = (-3.1, -60.02)

terrestrialDistance(48.87, 2.33, -3.1, -60.02) = 8314.25 Km

Hope it helps.
Publicado el 18,marzo 2016 - 19:04
Thanks guys

I had decided to store in three fields using DMS. And then use the formula to convert. Thanks for the extra ideas as well.

Cheers
Andre