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.
$rexp = '/^(\-?\d+(?:\.\d+)?)(?:\D+(\d+)\D+(\d+)([NS]?))?[^\d\-]+(\-?\d+(?:\.\d+)?)(?:\D+(\d+)\D+(\d+)([EW]?))?$/i';
$data = array(
"21° 16' 674S, 27° 30' 318E" ,
'21 16 674S, 27 30 318E' ,
'9.182, -39.140625' ,
'9.182 / -39.140625' ,
'9.182,-39.140625' ,
'9.182 -39.140625'
);
foreach( $data as $test ) {
if( !preg_match( $rexp , $test , $matches ) ) {
echo '<b>Failed</b>';
} else {
// Match Found
}
}
Outputs:
array(
[0] => Matched Text ,
[1] => Full Degrees ,
[2] => Minutes ,
[3] => Seconds ,
[4] => Hemisphere (N or S) ,
[5] => Full Degrees ,
[6] => Minutes ,
[7] => Seconds ,
[8] => Hemisphere (E or W)
)
Example:
// Matching 21° 16' 674S, 27° 30' 318E
array(
[0] => "21° 16' 674S, 27° 30' 318E" ,
[1] => "21" , [2] => "16" , [3] => "674" , [4] => "S" ,
[5] => "27" , [6] => "30" , [7] => "318" , [8] => "E"
)
// Matching 21 16 674S, 27 30 318E
array(
[0]=> "21 16 674S, 27 30 318E" ,
[1]=> "21" , [2]=> "16" , [3]=> "674" , [4]=> "S" ,
[5]=> "27" , [6]=> "30" , [7]=> "318" , [8]=> "E"
)
// Matching 9.182, -39.140625
array(
[0]=> "9.182, -39.140625" ,
[1]=> "9.182" , [2]=> "" , [3]=> "" , [4]=> "" ,
[5]=> "-39.140625" , [6]=> "" , [7]=> "" , [8]=> ""
)
// Matching 9.182 / -39.140625
array(
[0]=> "9.182 / -39.140625" ,
[1]=> "9.182" , [2]=> "" , [3]=> "" , [4]=> "" ,
[5]=> "-39.140625" , [6]=> "" , [7]=> "" , [8]=> ""
)
// Matching 9.182,-39.140625
array(
[0]=> "9.182,-39.140625" ,
[1]=> "9.182" , [2]=> "" , [3]=> "" , [4]=> "" ,
[5]=> "-39.140625" , [6]=> "" , [7]=> "" , [8]=> ""
)
// Matching 9.182 -39.140625
array(
[0]=> "9.182 -39.140625" ,
[1]=> "9.182" , [2]=> "" , [3]=> "" , [4]=> "" ,
[5]=> "-39.140625" , [6]=> "" , [7]=> "" , [8]=> ""
)
You could then, subsequently, process the results of the Regular Expression, to produce a float for the Lat/Long link so:
// (Replacing the "Match Found" comment)
$latitude = $matches[1]+((int)$matches[2]/60)+((int)$matches[3]/3600)*(strtolower($matches[4])=='s'?-1:1);
$longitude = $matches[5]+((int)$matches[6]/60)+((int)$matches[7]/3600)*(strtolower($matches[8])=='w'?-1:1);
Which produces:
// Matching 21° 16' 674S, 27° 30' 318E
$latitude = 21.4538888889
$longitude = 27.5883333333
// Matching 21 16 674S, 27 30 318E
$latitude = 21.4538888889
$longitude = 27.5883333333
// Matching 9.182, -39.140625
$latitude = 9.182
$longitude = -39.140625
// Matching 9.182 / -39.140625
$latitude = 9.182
$longitude = -39.140625
// Matching 9.182,-39.140625
$latitude = 9.182
$longitude = -39.140625
// Matching 9.182 -39.140625
$latitude = 9.182
$longitude = -39.140625