i’m trying to built in support for locations in my application and i’m expecting users to be inputting gps coordinates in a variety of ways. I need to convert all of the below to: latitude – direction (N/s), degres, minutes, seconds; longitude (E/W) – degrees, minuts, seconds.
Note, each user input will be in a single line. I would like my users to input only in one single way, but ppl will definitely enter as one of the following…:
eg:
9.182, -39.140625
9.182 / -39.140625
9.182,-39.140625
9.182 -39.140625
21° 16′ 674S[some_separator]27° 30′ 318E
21 16 674S[some_separator]27 30 318E
[some_separator] may be a single space as well…
The final format needs to beas:
latitude.direction = south
latitude.degrees = 21
latitude.minutes = 16
latitude.seconds = 674
longitude.direction = east
longitude.degrees = 27
longitude.minutes = 30
longitude.seconds = 318
(a) what is the simplest way of asking ordinary-non-tech users to input the GPS coordinate?s
(b) how do i convert the above to the final format? any built in functions that handle these variations in data input?
i’ve seen GPS format in PHP – but i need to handle a more varied input.
I have been working around with this further (and I notice that you edited your question).
A) What is the simplest way of asking ordinary-non-tech users to input the GPS coordinates?
The simplest, and most user friendly fashion for getting non-tech users to enter details would be using Google Maps. This would allow for you to use the Google Geocoder to parse their input (and provide a more standardised and formatted output). Further, if the location the user is inputting is their current location, you could look at using the Geolocation functionality offered by some of the modern browsers.
B) How do i convert the above to the final format? Any built in functions that handle these variations in data input?
Based on your test data, I have formulated a PHP Regular Expression to parse it and return a predictable and standardised output.
Outputs:
Example:
You could then, subsequently, process the results of the Regular Expression, to produce a float for the Lat/Long link so:
Which produces: