Posted By

tomelders on 03/10/11


Tagged

php coordinates


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

janwebdev


Convert Decimal Degrees to Degrees, Minutes & Seconds Ordinal


 / Published in: PHP
 

  1. decimalToOrdinalCoords(-45.42085,-12.196766);
  2.  
  3. function decimalToOrdinalCoords($lat, $lon){
  4.  
  5. $ordinalNS = ($lat > 0) ? "N" : "S";
  6. $ordinalEW = ($lon > 0) ? "E" : "W";
  7.  
  8. $deg = "°";
  9. $min = "’";
  10. $sec = "”";
  11.  
  12.  
  13. $latDeg = ($lat > 0) ? abs( floor($lat) ) : abs( ceil($lat) );
  14. $latMin = abs( ($lat - floor($lat)) * 60 );
  15. $latSec = abs( ($latMin - floor($latMin)) * 60 );
  16.  
  17. $degLatValue = $latDeg . $deg . floor($latMin) . $min . floor($latSec) . $sec . $ordinalNS;
  18.  
  19. $lonDeg = ($lon > 0) ? abs( floor($lon)) : abs( ceil($lon));
  20. $lonMin = abs( ($lon - floor($lon)) * 60 );
  21. $lonSec = abs( ($lonMin - floor($lonMin)) * 60 );
  22.  
  23. $degLonValue = $lonDeg . $deg . floor($lonMin) . $min . floor($lonSec) . $sec . $ordinalEW;
  24.  
  25. return $degLatValue . " " . $degLonValue;
  26.  
  27. }

Report this snippet  

You need to login to post a comment.