Reputation: 11768
I have a gps device witch outputs coordonates such as this : 4425.7819N 02607.5766E .
How can I convert them to normal latitude and longitude using PHP ? eg . 44.432395,26.125751
Upvotes: 2
Views: 2975
Reputation: 6394
Seems your GPS device outputs in MinDec format.
See under "Conversion from MinDec to Decimal Degree" at http://en.wikipedia.org/wiki/Geographic_coordinate_conversion for information.
Update:
See the following function that I have written to convert it for you:
function convert($input)
{
$input = ltrim($input, 0);
$mCount = preg_match('/([0-9]{2})([^NESW]+)(N|E|S|W)/', $input, &$matches);
if($mCount > 0)
{
$deg = intval($matches[1]);
$degMin = floatval($matches[2]) / 60;
$ret = $deg + $degMin;
return ($matches[3] == 'S' || $matches[3] == 'W' ? '-' : '') . $ret;
}
return null;
}
var_dump(convert('4425.7819N'));
var_dump(convert('02607.5766E'));
Hope that helps?
Upvotes: 4