decimaltodms.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
# referentiepunt: https://www.javawa.nl/coords.html
function decimalToDMS($decimal, $isLatitude) {
if ($isLatitude) {
$h = ($decimal >= 0) ? 'N' : 'S';
} else {
$h = ($decimal >= 0) ? 'E' : 'W';
}
$decimaal = round($decimal,5);
$graden_explode = explode(".", $decimaal);
$graden = abs(intval($graden_explode[0]));
$uren = $graden_explode[1];
//$minuten = round($uren*60/100000,3);
$minuten = round((('0.'.$uren)*60),3);
if ($isLatitude) {
$graden = $graden;
} else {
$graden = sprintf("%'.03d", $graden);
}
//cho 'Decimaal: '.$decimaal.'<br/>';
//echo 'Graden: '.$graden.'<br/>';
//echo 'Graden: '.$graden_explode[1].'<br/>';
//echo 'h ddd.ddddd° (graden): '.$h.' '.$graden.'.'.$uren.'°<br/>';
//echo 'h ddd° mm.mmm\' (graden en minuten): '.$h.' '.$graden.'° '.$minuten.'\'<br/>';
$full_format = ''.$h.''.$graden.'° '.$minuten.'';
return $full_format;
}
$latitude = 47.8297;
$longitude = -3.696766;
//$latitude = 53.568783;
//$longitude = 6.749766;
$dmsLatitude = decimalToDMS($latitude, true);
$dmsLongitude = decimalToDMS($longitude, false);
echo "Breedtegraad: $dmsLatitude<br>";
echo "Lengtegraad: $dmsLongitude<br>";
?>
# referentiepunt: https://www.javawa.nl/coords.html
function decimalToDMS($decimal, $isLatitude) {
if ($isLatitude) {
$h = ($decimal >= 0) ? 'N' : 'S';
} else {
$h = ($decimal >= 0) ? 'E' : 'W';
}
$decimaal = round($decimal,5);
$graden_explode = explode(".", $decimaal);
$graden = abs(intval($graden_explode[0]));
$uren = $graden_explode[1];
//$minuten = round($uren*60/100000,3);
$minuten = round((('0.'.$uren)*60),3);
if ($isLatitude) {
$graden = $graden;
} else {
$graden = sprintf("%'.03d", $graden);
}
//cho 'Decimaal: '.$decimaal.'<br/>';
//echo 'Graden: '.$graden.'<br/>';
//echo 'Graden: '.$graden_explode[1].'<br/>';
//echo 'h ddd.ddddd° (graden): '.$h.' '.$graden.'.'.$uren.'°<br/>';
//echo 'h ddd° mm.mmm\' (graden en minuten): '.$h.' '.$graden.'° '.$minuten.'\'<br/>';
$full_format = ''.$h.''.$graden.'° '.$minuten.'';
return $full_format;
}
$latitude = 47.8297;
$longitude = -3.696766;
//$latitude = 53.568783;
//$longitude = 6.749766;
$dmsLatitude = decimalToDMS($latitude, true);
$dmsLongitude = decimalToDMS($longitude, false);
echo "Breedtegraad: $dmsLatitude<br>";
echo "Lengtegraad: $dmsLongitude<br>";
?>