I have read and downloaded the Haversine Formula in the Algorithims snippets and this doesn't take care of my problem.

I wish to allow users to enter their lat/lon coordinates in either decimal degrees or degrees and decimal minutes. Most users are familiar with using degrees and decimal minutes, but, for mapping and download purposes, I need all coordinates in decimal minutes. I also have 100s of thousands of lat/lon coordinates I need to convert to degrees and decimal minutes. I would like the user to be able to select the view of either decimal degrees or degree and decimal minutes.

I have the following javascript which converts decimal degrees to degrees, minutes, seconds.

Does anyone know if and how to adapt this script to php? I saw in the PHP Manual that PHP would support float in version 4.2, but, is it possible with the version we have here?

Problem #2 is to allow a user to select a set of coordinates and parse those coordinates to an xml file. I'll post the format it needs to be in below.

Thanks in advance for your help.

The following contains the javascript on an independent page allowing a user to convert individual files, but, what I need is to allow them to input their coordinates into a form with many other items and have the coordinates converted for my database.



<head><script LANGUAGE="JavaScript">
<!-- Hide JavaScript from Java-Impaired Browsers

			var defaultEmptyOK = true;
			var decimalPointDelimiter = ".";

			function isDigit (c)
			{   return ((c >= "0") && (c <= "9")) }

			function isEmpty(s)
			{   return ((s == null) || (s.length == 0)); }

			function isFloat (s)
			{   var i;
			    var seenDecimalPoint = false;
				 if (isEmpty(s))
   				if (isFloat.arguments.length == 1) return defaultEmptyOK;
   				else return (isFloat.arguments[1] == true);
				 if (s == decimalPointDelimiter) return false;
				 for (i = 0; i < s.length; i++)
				 {   var c = s.charAt(i);
    				  if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
    				  else if (!isDigit(c)) return false;
				 }
				 return true;
			}

			function isSignedFloat (s)
			{   if (isEmpty(s))
   				if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;
   				else return (isSignedFloat.arguments[1] == true);
				 else {
    				var startPos = 0;
    				var secondArg = defaultEmptyOK;
    				if (isSignedFloat.arguments.length > 1)
        				secondArg = isSignedFloat.arguments[1];
    				if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
       				startPos = 1;
    				return (isFloat(s.substring(startPos, s.length), secondArg))
				}
			}

			function warnInvalid (theField, s)
				{   theField.focus()
				theField.select()
				alert(s)
				return false
			}

          var dec = 0 ;
          var deg = 0 ;
          var min = 0 ;
          var sec = 0 ;

          function convert(form) {
            with (form) {
                 if  (!(isSignedFloat (DECIMAL.value))) {
                       warnInvalid (DECIMAL, "Decimal Degrees need to be a Numerical value (Between -180 and 180) "); return false; }

                 if  (DECIMAL.value < -180) {
                       warnInvalid (DECIMAL, "Decimal Degrees need to be a Numerical value (Between -180 and 180) "); return false; }

                 if  (DECIMAL.value > 180) {
                       warnInvalid (DECIMAL, "Decimal Degrees need to be a Numerical value (Between -180 and 180) "); return false; }

                 if (DECIMAL.value < 0 ) {
                     dec = Math.abs(DECIMAL.value);
                     deg = Math.floor(dec);
                     min = Math.floor((dec - deg) * 60) ;
                     sec = Math.floor((dec - deg - (min/60)) * 3600) ;
                     deg = 0 - deg ; }
                 else {
                     dec = Math.abs(DECIMAL.value);
                     deg = Math.floor(dec);
                     min = Math.floor((dec - deg) * 60) ;
                     sec = Math.floor((dec - deg - (min/60)) * 3600) ; }

                 DEG.value = deg ;
                 MIN.value = min ;
                 SEC.value = sec ;                     

					return false;
                 }
           }
// End Hiding -->
</script>

<title>AADC - Degrees Minutes Seconds to Decimal Conversion Calculator</title>
<link rel="stylesheet" href="http://www.aad.gov.au/css/aad.css">
		<link rel="stylesheet" href="http://www.aad.gov.au/css/sci.css">
	</head>

<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<a name="top"></a>

<p></P>  
<p></P> <p></P>
<div class="text"> <form align="center" onSubmit="return convert(this)"> <div align="center"> <center> <table BORDER="1"> <tr> <td ALIGN="CENTER"><strong> Decimal Degrees to Degrees Minutes Seconds</strong></td> </tr> <tr> <td VALIGN="TOP"> <p align="center">Decimal : <input TYPE="text" NAME="DECIMAL" SIZE="40"></td> </tr> <tr> <td ALIGN="CENTER" VALIGN="TOP"> <input TYPE="submit" VALUE=" Click for Conversion "> <input TYPE="reset" VALUE=" Reset Values "></td> </tr> <tr> <td ALIGN="CENTER" VALIGN="TOP">Degrees Minutes Seconds :-&nbsp;<input type="text" name="DEG" size="3">°&nbsp;<input type="text" name="MIN" size="3">'&nbsp;<input type="text" name="SEC" size="3">&quot; </td> </tr> </table> </center> </div> </form> </div> </BODY>

The following is the format the coordinates would have to be placed for export. I want the users to be able to download the coordinates into a format whereby they can upload the coordinates to their GPS using the free utility EasyGPS. Dan Foster of Topographix provided me with this example.

The GPX format is explained at http://www.topografix.com/gpx.asp

Here's a sample conversion:
State Type Name Latitude Longitude
GA NAV/BOUY WRECK 3201.00002 8048
GA NAV/BOUY Cr Obs BY 3 3200.83334 8053.05002

Write the header, which will be the same for all your GPX files:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<gpx
 version="1.0"
 creator="Coastal Outdoors - [url]http://www.coastaloutdoors.com[/url]"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://www.topografix.com/GPX/1/0"
 xsi:schemaLocation="http://www.topografix.com/GPX/1/0 [url]http://www.topografix.com/GPX/1/0/gpx.xsd[/url]">

Write out the two waypoints:
<wpt lat="32.016666667" lon="-80.800000000">
 <desc><![CDATA[WRECK]]></desc>
 <type><![CDATA[NAV/BOUY]]></type>
</wpt>
<wpt lat="32.013883333" lon="-80.884166667">
 <desc><![CDATA[Cr Obs]]></desc>
 <type><![CDATA[NAV/BOUY]]></type>
</wpt>

Write out the closing GPX tag:
</gpx>


The final GPX document looks like:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<gpx
 version="1.0"
 creator="Coastal Outdoors - [url]http://www.coastaloutdoors.com[/url]"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://www.topografix.com/GPX/1/0"
 xsi:schemaLocation="http://www.topografix.com/GPX/1/0 [url]http://www.topografix.com/GPX/1/0/gpx.xsd[/url]">
<wpt lat="32.016666667" lon="-80.800000000">
 <desc><![CDATA[WRECK]]></desc>
 <type><![CDATA[NAV/BOUY]]></type>
</wpt>
<wpt lat="32.013883333" lon="-80.884166667">
 <desc><![CDATA[Cr Obs]]></desc>
 <type><![CDATA[NAV/BOUY]]></type>
</wpt>
</gpx>
    Write a Reply...