代码:
print_r(parse("40.0873°N 20.1531°E"));
print_r(parse("27°50′21″N 00°11′07″W"));
function parse($coord)
{
$strings = split(' ',$coord);
$ret['lat'] = degree2decimal($strings[0]);
$ret['lon'] = degree2decimal($strings[1]);
return $ret;
}
function degree2decimal($deg_coord="")
{
$dpos=strpos($deg_coord,'°');
$mpos=strpos($deg_coord,'‘');
$spos=strpos($deg_coord,'"');
$mlen=(($mpos-$dpos)-1);
$slen=(($spos-$mpos)-1);
$direction=substr(strrev($deg_coord),0,1);
$degrees=substr($deg_coord,0,$dpos);
$minutes=substr($deg_coord,$dpos+1,$mlen);
$seconds=substr($deg_coord,$mpos+1,$slen);
$seconds=($seconds/60);
$minutes=($minutes+$seconds);
$minutes=($minutes/60);
$decimal=($degrees+$minutes);
if (($direction=="S") or ($direction=="W"))
{ $decimal=$decimal*(-1);}
return $decimal;
}
输出:
Array
(
[lat] => 40.08732425
[lon] => 20.153142527778
)
Array
(
[lat] => 27.835277777778
[lon] => -0.18333333333333
)