hellouthere Posted March 3, 2007 Share Posted March 3, 2007 Hi all, I need a function that will convert a latitude/longditue stored in the variable $position in the format "N50 43.9122 W3 25.6329" to two seperate coordinates $lat and $long which can be read by the google maps api... http://www.google.com/apis/maps/documentation/ thats all the information i have... Thanks in advance... Quote Link to comment https://forums.phpfreaks.com/topic/41022-solved-coordinate-conversion/ Share on other sites More sharing options...
tippy_102 Posted March 4, 2007 Share Posted March 4, 2007 A minute is 1/60 of a degree so 43.9122 / 60 = 0.73187 $lat = ($degrees + ($minutes/60)); Quote Link to comment https://forums.phpfreaks.com/topic/41022-solved-coordinate-conversion/#findComment-198961 Share on other sites More sharing options...
hellouthere Posted March 4, 2007 Author Share Posted March 4, 2007 the variable is in that format and i cant change it.... i need to be able to split it... i can use the full stops but i cannot get the N50 apart... any ideas for that? Quote Link to comment https://forums.phpfreaks.com/topic/41022-solved-coordinate-conversion/#findComment-198986 Share on other sites More sharing options...
Barand Posted March 4, 2007 Share Posted March 4, 2007 <?php $position = "N50 43.9122 W3 25.6329"; list ($n, $lat, $w, $long) = explode (' ', $position); echo $lat, '<br/>'; // 43.9122 echo $long, '<br/>'; // 25.6329 ?> Quote Link to comment https://forums.phpfreaks.com/topic/41022-solved-coordinate-conversion/#findComment-198994 Share on other sites More sharing options...
hellouthere Posted March 4, 2007 Author Share Posted March 4, 2007 o may be mising omething but that still leaves the problem of not having acces to the 50 seperately... i have trried using barands "explode with the /60 but the coordinates are not "corrrect" as it were not sure whether its actually possible... i have woprked out that the coordinate that i need from the above example are... lng="-3.427215" lat="50.73187" the function needs to seperate the N50 from the 43.9122... DONE divide the 43.9122 by 60... DONE add the 50 (from the N50)... ??? work out whether the final rersult is + or - based on the W/E (W is negative i think)... ??? hmm im lost Quote Link to comment https://forums.phpfreaks.com/topic/41022-solved-coordinate-conversion/#findComment-199017 Share on other sites More sharing options...
Barand Posted March 4, 2007 Share Posted March 4, 2007 given that you start with $position = "N50 43.9122 W3 25.6329"; What, precisely, do you want to end up with? Quote Link to comment https://forums.phpfreaks.com/topic/41022-solved-coordinate-conversion/#findComment-199018 Share on other sites More sharing options...
Barand Posted March 4, 2007 Share Posted March 4, 2007 do you mean <?php $position = "N50 43.9122 W3 25.6329"; list ($n, $latmin, $w, $longmin) = explode (' ', $position); printf ('%s, %d, %f<br>', $n{0}, substr($n,1), $latmin); printf ('%s, %d, %f<br>', $w{0}, substr($w,1), $longmin); ?> -->[pre] N, 50, 43.912200 W, 3, 25.632900 [/pre] Quote Link to comment https://forums.phpfreaks.com/topic/41022-solved-coordinate-conversion/#findComment-199020 Share on other sites More sharing options...
hellouthere Posted March 4, 2007 Author Share Posted March 4, 2007 thats all i need i think barand... i jut needed the N seperate... thanks alot... ill create the final function now... Quote Link to comment https://forums.phpfreaks.com/topic/41022-solved-coordinate-conversion/#findComment-199141 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.