Skip to content

Instantly share code, notes, and snippets.

@johnteee
Forked from will83/index.php
Created October 12, 2022 04:17
Show Gist options
  • Save johnteee/dcb682fdc942af35983cb00aaac07734 to your computer and use it in GitHub Desktop.
Save johnteee/dcb682fdc942af35983cb00aaac07734 to your computer and use it in GitHub Desktop.

Revisions

  1. @will83 will83 revised this gist Dec 14, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ function WGS84toGPS($lat, $lng){
    $sec = ($decimals * .6) - $min; // (6.52584) - 6 // 0.52584
    $sec = round($sec*60, 1); // round(31.5504, 1) // 31.6
    $min = ($min >= 10) ? $min : '0'.$min;
    $sec = ($sec >= 1) ? $sec : '0'.$sec;
    $sec = ($sec >= 10) ? $sec : '0'.$sec;

    $gps_lat = $whole.'°'.$min.'\''.$sec.'"'.$lat_card;

    @@ -28,7 +28,7 @@ function WGS84toGPS($lat, $lng){
    $sec = ($decimals * .6) - $min; // (6.52584) - 6 // 0.52584
    $sec = round($sec*60, 1); // round(31.5504, 1) // 31.6
    $min = ($min >= 10) ? $min : '0'.$min;
    $sec = ($sec >= 1) ? $sec : '0'.$sec;
    $sec = ($sec >= 10) ? $sec : '0'.$sec;

    $gps_lng = $whole.'°'.$min.'\''.$sec.'"'.$lng_card;

  2. @will83 will83 revised this gist Dec 12, 2017. 1 changed file with 11 additions and 9 deletions.
    20 changes: 11 additions & 9 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -8,25 +8,27 @@ function WGS84toGPS($lat, $lng){

    // define latitude coordinate with minutes and seconds
    $lat_card = ($lat > 0) ? 'N' : 'S';
    $whole = abs(floor($lat)); // x digits before coma // 24
    $decimals = $lat - $whole; // 6 digits after coma // 108764
    $whole = ($lat > 0) ? abs(floor($lat)) : abs(ceil($lat)); // x digits before coma // 24
    $decimals = (abs($lat) - $whole) * 100; // 6 digits after coma // 108764

    $min = floor($decimals * .00006); // floor(6.52584) // 6
    $sec = ($decimals * .00006) - $min; // (6.52584) - 6 // 0.52584
    $min = floor($decimals * .6); // floor(6.52584) // 6
    $sec = ($decimals * .6) - $min; // (6.52584) - 6 // 0.52584
    $sec = round($sec*60, 1); // round(31.5504, 1) // 31.6
    $min = ($min >= 10) ? $min : '0'.$min;
    $sec = ($sec >= 1) ? $sec : '0'.$sec;

    $gps_lat = $whole.'°'.$min.'\''.$sec.'"'.$lat_card;

    // define longitude coordinate with minutes and seconds
    $lng_card = ($lng > 0) ? 'W' : 'E';
    $whole = abs(floor($lng)); // x digits before coma // 16
    $decimals = $lng - $whole; // 6 digits after coma // 500156
    $lng_card = ($lng > 0) ? 'E' : 'W';
    $whole = ($lng > 0) ? abs(floor($lng)) : abs(ceil($lng)); // x digits before coma // 16
    $decimals = (abs($lng) - $whole) * 100; // 6 digits after coma // 500156

    $min = floor($decimals * .00006); // floor(6.52584) // 6
    $sec = ($decimals * .00006) - $min; // (6.52584) - 6 // 0.52584
    $min = floor($decimals * .6); // floor(6.52584) // 6
    $sec = ($decimals * .6) - $min; // (6.52584) - 6 // 0.52584
    $sec = round($sec*60, 1); // round(31.5504, 1) // 31.6
    $min = ($min >= 10) ? $min : '0'.$min;
    $sec = ($sec >= 1) ? $sec : '0'.$sec;

    $gps_lng = $whole.'°'.$min.'\''.$sec.'"'.$lng_card;

  3. @will83 will83 revised this gist Dec 12, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.php
    Original file line number Diff line number Diff line change
    @@ -30,5 +30,5 @@ function WGS84toGPS($lat, $lng){

    $gps_lng = $whole.'°'.$min.'\''.$sec.'"'.$lng_card;


    return $gps_lat.' '.$gps_lng;
    }
  4. @will83 will83 revised this gist Dec 12, 2017. 1 changed file with 32 additions and 3 deletions.
    35 changes: 32 additions & 3 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,34 @@
    <?php
    $lat = 43.1166700;
    $long = 5.9333300;
    $lat = -24.108764;
    $lng = 16.500156;


    function WGS84toGPS($lat, $lng){
    $lat = number_format($lat, 6);
    $lng = number_format($lng, 6);

    // define latitude coordinate with minutes and seconds
    $lat_card = ($lat > 0) ? 'N' : 'S';
    $whole = abs(floor($lat)); // x digits before coma // 24
    $decimals = $lat - $whole; // 6 digits after coma // 108764

    $min = floor($decimals * .00006); // floor(6.52584) // 6
    $sec = ($decimals * .00006) - $min; // (6.52584) - 6 // 0.52584
    $sec = round($sec*60, 1); // round(31.5504, 1) // 31.6
    $min = ($min >= 10) ? $min : '0'.$min;

    $gps_lat = $whole.'°'.$min.'\''.$sec.'"'.$lat_card;

    // define longitude coordinate with minutes and seconds
    $lng_card = ($lng > 0) ? 'W' : 'E';
    $whole = abs(floor($lng)); // x digits before coma // 16
    $decimals = $lng - $whole; // 6 digits after coma // 500156

    $min = floor($decimals * .00006); // floor(6.52584) // 6
    $sec = ($decimals * .00006) - $min; // (6.52584) - 6 // 0.52584
    $sec = round($sec*60, 1); // round(31.5504, 1) // 31.6
    $min = ($min >= 10) ? $min : '0'.$min;

    $gps_lng = $whole.'°'.$min.'\''.$sec.'"'.$lng_card;


    }
  5. @will83 will83 revised this gist Dec 12, 2017. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion index.php
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,5 @@
    <?php
    $lat
    $lat = 43.1166700;
    $long = 5.9333300;


  6. @will83 will83 revised this gist Dec 12, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@

    $lat
    <?php
    $lat
  7. @will83 will83 created this gist Dec 12, 2017.
    2 changes: 2 additions & 0 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@

    $lat