PHP: Latitude va Longitude darajasini darajalar, minutlar va sekundlar bilan

Buni qanday qilib o'zgartirishi mumkin:

26.72773551940918

Shu kabi bir narsaga:

22°12'42"N

Bu erdagi koordinatalar, aslida Latitude va Longitude, men ularni to'g'ri formatlashim kerak.

6

4 javoblar

You can find functions to do that here

<?php

function DMStoDEC($deg,$min,$sec)
{

// Converts DMS ( Degrees/minutes/seconds ) 
// to decimal format longitude/latitude

    return $deg+((($min*60)+($sec))/3600);
}    

function DECtoDMS($dec)
{

// Converts decimal longitude/latitude to DMS
// ( Degrees/minutes/seconds ) 

// This is the piece of code which may appear to 
// be inefficient, but to avoid issues with floating
// point math we extract the integer part and the float
// part by using a string function.

    $vars = explode(".",$dec);
    $deg = $vars[0];
    $tempma = "0.".$vars[1];

    $tempma = $tempma * 3600;
    $min = floor($tempma/60);
    $sec = $tempma - ($min*60);

    return array("deg"=>$deg,"min"=>$min,"sec"=>$sec);
}    

?>
14
qo'shib qo'ydi
@SERPRO: farqlarni kamaytirishni bilasizmi, degrees va DMS o'rtasidagi konvertatsiya nima bo'ladi?
qo'shib qo'ydi muallif secretlm, manba
Salomat bo'ling! :)
qo'shib qo'ydi muallif SERPRO, manba
Rahmat! Bu ish kabi ko'rinadi!
qo'shib qo'ydi muallif ragulka, manba

Lat/lon koordinatorlari taxminan 60 ga asoslangan raqamli tizim da yoziladi. Siz ularni qanday qilib o'zgartirasiz:

function fraction_to_min_sec($coord)
{
  $isnorth = $coord>=0;
  $coord = abs($coord);
  $deg = floor($coord);
  $coord = ($coord-$deg)*60;
  $min = floor($coord);
  $sec = floor(($coord-$min)*60);
  return array($deg, $min, $sec, $isnorth ? 'N' : 'S');
 //or if you want the string representation
  return sprintf("%d°%d'%d\"%s", $deg, $min, $sec, $isnorth ? 'N' : 'S');
}

Men o'zimning vazifam @ SeRPRo'ga qaraganda yaxshiroq soni barqarorligini aytayapman.

6
qo'shib qo'ydi
Kechirasiz, bu yozuv tipi.
qo'shib qo'ydi muallif Leonid Shevtsov, manba
@ragulka, en.wikipedia.org/wiki/Longitude : "Hisoblash uchun G'arbiy/Sharqiy qo'shimchani G'arbiy yarim sharda salbiy belgilar bilan almashtiriladi. "
qo'shib qo'ydi muallif Leonid Shevtsov, manba
Mening javobimdagi kod meniki emas, topilgan vazifadir. Funktsiyangiz haqida yaxshi yoki yo'qligini bilmayman, lekin "$ whole" o'zgaruvchining qaerdan kelganini bilmayman.
qo'shib qo'ydi muallif SERPRO, manba
Hey, g'arbdan yoki sharqdanmi?
qo'shib qo'ydi muallif ragulka, manba

DMS qiymatlarida kenglik, uzunlik oralig'ida o'tgan va aylantirilgan DMS mag'lubiyatini qaytaradigan joy. Oddiy va sodda

function DECtoDMS($latitude, $longitude)
{
    $latitudeDirection = $latitude < 0 ? 'S': 'N';
    $longitudeDirection = $longitude < 0 ? 'W': 'E';

    $latitudeNotation = $latitude < 0 ? '-': '';
    $longitudeNotation = $longitude < 0 ? '-': '';

    $latitudeInDegrees = floor(abs($latitude));
    $longitudeInDegrees = floor(abs($longitude));

    $latitudeDecimal = abs($latitude)-$latitudeInDegrees;
    $longitudeDecimal = abs($longitude)-$longitudeInDegrees;

    $_precision = 3;
    $latitudeMinutes = round($latitudeDecimal*60,$_precision);
    $longitudeMinutes = round($longitudeDecimal*60,$_precision);

    return sprintf('%s%s° %s %s %s%s° %s %s',
        $latitudeNotation,
        $latitudeInDegrees,
        $latitudeMinutes,
        $latitudeDirection,
        $longitudeNotation,
        $longitudeInDegrees,
        $longitudeMinutes,
        $longitudeDirection
    );

}
2
qo'shib qo'ydi

DMS mag'lubiyatga ega bo'lsangiz va float raqami (unicode belgilarni o'z ichiga olgan holda) kerak bo'lsa, buning teskarisi:

//e.g.
$dec = dms_to_dec("-18° 51' 30.5697\"");

/**
 * Convert a coordinate in dms to dec
 *
 * @param string $dms coordinate
 * @return float
 */
function dms_to_dec($dms)
{
    $dms = stripslashes($dms);
    $neg = (preg_match('/[SWO]/i', $dms) == 0) ? 1 : -1;
    $dms = preg_replace('/(^\s?-)|(\s?[NSEWO]\s?)/i', '', $dms);
    $pattern = "/(\\d*\\.?\\d+)(?:[°ºd: ]+)(\\d*\\.?\\d+)*(?:['m′: ])*(\\d*\\.?\\d+)*[\"s″ ]?/i";
    $parts = preg_split($pattern, $dms, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
    if (!$parts) {
        return;
    }
   //parts: 0 = degree, 1 = minutes, 2 = seconds
    $d = isset($parts[0]) ? (float)$parts[0] : 0;
    $m = isset($parts[1]) ? (float)$parts[1] : 0;
    if (strpos($dms, ".") > 1 && isset($parts[2])) {
        $m = (float)($parts[1] . '.' . $parts[2]);
        unset($parts[2]);
    }
    $s = isset($parts[2]) ? (float)$parts[2] : 0;
    $dec = ($d + ($m/60) + ($s/3600))*$neg; 
    return $dec;
}
0
qo'shib qo'ydi
PhP |BotsUz
PhP |BotsUz
93 ishtirokchilar

Phpni o'rganishni Hohlasangiz https://t.me/joinchat/AAAAAE-KRc5dd5tPMmGmWA A'zo bo'lin