Latitude/Longtitude waarden omzetten die google maps gebruikt
weet iemand hoe deze formule in elkaar zit?
Google map gebruikt zgn. x,y waarden (bv. 50.267831, 5.3864673)
Ik haal data uit de exif gegevens en die zijn in het volgende formaat
Longtitude in 4 variabelen, 1) graden 2) minuten 3) seconden 4) halfrond (E/W)
bv. 5 (graden), 42 (minuten), 57 (seconden), E (Oost)
Latitude idem maar dan halfrond N/S.
bv. 50 (graden), 48 (minuten), 13 (seconden), N (Noord)
Ik ga ervan uit East de Longtitude negatief maakt net zoals South voor Latitude.
Nu de hamvraag
Wat is de juiste formule om deze correct om te zetten naar het x,y formaat die Googlemaps(of Earth) gebruikt?
Heb al gegoogled maar ik wordt gek van de tegenstrijdigheden.
Sin, Cosinus, PI etc. etc.
http://en.wikipedia.org/wiki/Wikipedia:Obtaining_geographic_coordinates en misschien deze om wat javascript te achterhalen: http://www.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html en deze voor een complete source: http://www.lynedochpublications.com.au/radiosites/inc/dms2decimal.txt
Gewijzigd op 18/08/2010 11:22:45 door John D
Moet het nog ff uittesten op afwijkingen.
<code>
<html>
<head>
<title>PHP functie omrekenen latitude en logtitude naard decimaal waarden (googlemaps)</title>
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
// ----------------------------------------------------------------------------
//
// Convert a latitude and longtitude, expressed in dms, to decimal degrees
//
// ----------------------------------------------------------------------------
// Translation to PHP and minor modifications by J. C. Parker, 2007
// ----------------------------------------------------------------------------
// Convert a latitude and longtitude, expressed in dms, to decimal degrees
// ----------------------------------------------------------------------------
function dms2decimal($dmsStr)
{
// get rid of pre and post white space
$dmsStr= trim($dmsStr);
// already a number of "some description", if so return it
if (is_numeric($dmsStr)) return (float)$dmsStr;
// look for a cardinal point (NSEW) as the very last character
$cp = strtoupper(substr($dmsStr,-1,1));
// remove the cardinal point if it exists
if (($cp == 'N')||($cp == 'S')||($cp == 'E')||($cp == 'W'))
$dmsStr = rtrim($dmsStr, $cp);
else
// if there is no NSEW, then we may have decimal degrees separated by a comma
$cp = '';
// split up the string at all the (probable) delimiters
// The only special characters inside a character class [] are ]\^- The usual
// metacharacters are normal characters inside a character class, and do not need
// to be escaped by a backslash. Match any white space using \s and match °:'º,"
$splitHere = "/[\s°:'º,\"]/";
$strPieces = preg_split($splitHere, $dmsStr);
// remove any blank pieces
$finalStr = array();
foreach ($strPieces as $var)
if ($var != '') $finalStr[] = $var;
// print the array for test purposes
//$results = print_r($finalStr, TRUE);
//error_log("$results\n", 3, LOG_FILE);
// default to a positive signed number
$sgn = 1.0;
// see how many pieces there are
$pieceCount = count($finalStr);
// does the first piece contain a negative sign char?
if ($pieceCount > 0)
{
// look for a sign as the very first character
$signChar = substr($finalStr[0],0,1);
// note the two different types of minus signs
if (($signChar == '-') || ($signChar == '-'))
{
$sgn = -1.0;
// remove the sign from the string
$finalStr[0] = substr($finalStr[0],1);
}
}
// act according to the number of pieces available
switch ($pieceCount)
{
case 3: // d.m.s
$decimalDegrees = $sgn*$finalStr[0] + $sgn*($finalStr[1]/60.0) + $sgn*($finalStr[2]/3600.0);
break;
case 2:
// d.m or decimal degrees with comma seperation ie European number format?
// If decimal degrees it must be two pieces, it will have no cardinal point
// associated with it and the pieces will be separated by a comma
if (($cp == '') && (strpos($dmsStr,',') !== FALSE))
// decimal degrees integer.fraction
$decimalDegrees = $sgn*(float)((string)$finalStr[0].'.'.(string)($finalStr[1]));
else
// d.m
$decimalDegrees = $sgn*$finalStr[0] + $sgn*($finalStr[1]/60.0);
break;
case 1: // +/-dddmmss
$length = strlen($finalStr[0]);
if (($length == 7) || ($length == 8))
{
$decimalDegrees = $sgn*(substr($finalStr[0],0,3)) // ddd
+ $sgn*(substr($finalStr[0],3,2) / 60.0) // mm
+ $sgn*(substr($finalStr[0],5) / 3600.0); // ss
}
else
return acos(1.01); // return NaN
break;
default:
return acos(1.01); // return NaN
}
// change the sign for S and W
if (($cp == 'S') || ($cp == 'W')) $decimalDegrees = -$decimalDegrees;
return $decimalDegrees;
}
?>
// ----------------------------------------------------------------------------
//
// Convert a latitude and longtitude, expressed in dms, to decimal degrees
//
// ----------------------------------------------------------------------------
// Translation to PHP and minor modifications by J. C. Parker, 2007
// ----------------------------------------------------------------------------
// Convert a latitude and longtitude, expressed in dms, to decimal degrees
// ----------------------------------------------------------------------------
function dms2decimal($dmsStr)
{
// get rid of pre and post white space
$dmsStr= trim($dmsStr);
// already a number of "some description", if so return it
if (is_numeric($dmsStr)) return (float)$dmsStr;
// look for a cardinal point (NSEW) as the very last character
$cp = strtoupper(substr($dmsStr,-1,1));
// remove the cardinal point if it exists
if (($cp == 'N')||($cp == 'S')||($cp == 'E')||($cp == 'W'))
$dmsStr = rtrim($dmsStr, $cp);
else
// if there is no NSEW, then we may have decimal degrees separated by a comma
$cp = '';
// split up the string at all the (probable) delimiters
// The only special characters inside a character class [] are ]\^- The usual
// metacharacters are normal characters inside a character class, and do not need
// to be escaped by a backslash. Match any white space using \s and match °:'º,"
$splitHere = "/[\s°:'º,\"]/";
$strPieces = preg_split($splitHere, $dmsStr);
// remove any blank pieces
$finalStr = array();
foreach ($strPieces as $var)
if ($var != '') $finalStr[] = $var;
// print the array for test purposes
//$results = print_r($finalStr, TRUE);
//error_log("$results\n", 3, LOG_FILE);
// default to a positive signed number
$sgn = 1.0;
// see how many pieces there are
$pieceCount = count($finalStr);
// does the first piece contain a negative sign char?
if ($pieceCount > 0)
{
// look for a sign as the very first character
$signChar = substr($finalStr[0],0,1);
// note the two different types of minus signs
if (($signChar == '-') || ($signChar == '-'))
{
$sgn = -1.0;
// remove the sign from the string
$finalStr[0] = substr($finalStr[0],1);
}
}
// act according to the number of pieces available
switch ($pieceCount)
{
case 3: // d.m.s
$decimalDegrees = $sgn*$finalStr[0] + $sgn*($finalStr[1]/60.0) + $sgn*($finalStr[2]/3600.0);
break;
case 2:
// d.m or decimal degrees with comma seperation ie European number format?
// If decimal degrees it must be two pieces, it will have no cardinal point
// associated with it and the pieces will be separated by a comma
if (($cp == '') && (strpos($dmsStr,',') !== FALSE))
// decimal degrees integer.fraction
$decimalDegrees = $sgn*(float)((string)$finalStr[0].'.'.(string)($finalStr[1]));
else
// d.m
$decimalDegrees = $sgn*$finalStr[0] + $sgn*($finalStr[1]/60.0);
break;
case 1: // +/-dddmmss
$length = strlen($finalStr[0]);
if (($length == 7) || ($length == 8))
{
$decimalDegrees = $sgn*(substr($finalStr[0],0,3)) // ddd
+ $sgn*(substr($finalStr[0],3,2) / 60.0) // mm
+ $sgn*(substr($finalStr[0],5) / 3600.0); // ss
}
else
return acos(1.01); // return NaN
break;
default:
return acos(1.01); // return NaN
}
// change the sign for S and W
if (($cp == 'S') || ($cp == 'W')) $decimalDegrees = -$decimalDegrees;
return $decimalDegrees;
}
?>
</head>
<body>
Code (php)
</body>
</html>
</code>
http://www.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html
Ik heb ooit een paar omzettingen handmatig gedaan en had dus nog wat bookmarks....
Je kan hier je tests mee verifieren/vergelijken. Dit werkt met andere (javascript) code. Ik heb ooit een paar omzettingen handmatig gedaan en had dus nog wat bookmarks....
Edit:
enne een off-topic vraag: Jouw fototoestel voegt dit automatisch aan de exif data toe ??
enne een off-topic vraag: Jouw fototoestel voegt dit automatisch aan de exif data toe ??
Gewijzigd op 18/08/2010 12:41:43 door John D
Ik weet niet of dat op een Can eos450d kan.
Maar daar moeten we het eens over hebben in de fotografie topic.
Als je even een tussenresultaat wilt zien waarmee ik bezig ben
http://www.renewennekes.com/pictures.php?catalog=new
Wat ik nu doe is met het gratis programma Geosetter de coordinaten vrij snel in 1 of meer foto's tegelijk m.b.v. kaart in de exif headers invoeren.
Uiteraard kan je ook m.b.v. een gps systeem de coordinaten even vastleggen op bv. papier.
Gewijzigd op 18/08/2010 16:55:18 door Rene Wennekes