Degrees, Minutes, and Seconds

See that? ↑ The location? We use a WordPress plugin called Geo by Owen Winkler to create that. By default the plugin produces decimal based coordinates like this: 42.0531007026558. Those are certainly functional. It’s what you need when you go all geo on Google Maps. It’s what most sites used for finding Lat/Lon will produce for you. But ultimately it’s just not that pretty.

I wanted to go with the Degrees, Minutes, Seconds format which just seems a little more polished. I imagine James Bond would use it in his blog posts. To do that I had to make a few changes to the file geo.php which allows for all of this. Mathematically, it’s pretty simple. You just take the integer portion of the number as the degrees and multiply by 60. Take the integer part of the number as the minutes and multiply by 60. The left overs are seconds.

Here’s the php code for the latitude:

$lat_deg = floor(get_Lat());
$lat_cut1 = get_Lat() – $lat_deg;
$lat_min1 = $lat_cut1*60;
$lat_min2 = floor($lat_min1);
$lat_cut2 = $lat_min1 – $lat_min2;
$lat_sec1 = $lat_cut2*60;
$lat_sec2 = floor($lat_sec1);
if(get_settings(‘use_geo_positions’)) {
if(get_Lat() > 0) {
echo “”.$lat_deg.”° “.$lat_min2.”‘ “.$lat_sec2.”””.”N”;
} else {
echo “”.$lat_deg.”° “.$lat_min2.”‘ “.$lat_sec2.”””.”S”;
}
}

The code for the longitude is basically the same. Now you have no excuse for getting lost on the way to our offices.