converting GPS latitude/longitude from different formats to one format (in PHP)

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-06-16T10:38:24Z Indexed on 2010/06/16 10:42 UTC
Read the original article Hit count: 261

Filed under:
|
|

Hi. 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.

Each user input will be in a single line.

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 http://stackoverflow.com/questions/2548943/gps-format-in-php - but i need to handle a more varied input.

© Stack Overflow or respective owner

Related posts about php

Related posts about geolocation