Jump to content

DMS to WGS84


MiCR0

Recommended Posts

I am trying to work out how to convert DMS to WGS84

 

I have the coordinate in mysql like

 

latitude                    longitude

52°39'03.1 N          0°40'36.1 E

52°46'45.2 N         0°06'59.9 W

 

I need to make them WGS84 and I find a functions

 

<?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);
}   

I had a go at it doing

$lat = explode("°",$data->latitude);
$lat2 = explode("'",$lat[1]);
$lat3 = explode(" ",$lat2[1]);

$longitude = explode("°",$data->longitudeitude);
$longitude2 = explode("'",$longitude[1]);
$longitude3 = explode(" ",$longitude2[1]);

	echo $lat['0'].'-'.$lat2[0].'-'.$lat3[0];
echo '<br/>';
echo $longitude['0'].'-'.$longitude[0].'-'.$longitude[0];

echo  DMStoDEC($lat['0'],$lat2[0],$lat3[0]); 
echo DMStoDEC($longitude['0'],$longitude2[0],$longitude3[0]);
?>

 

I am stuck any help would be great.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.