last update: 03/04/10 (dd/mm/yy)
back to www.TXTester.com

GPS Coord Calc API

Global Methods

Method Return Type Description
txtester.gpscoordcalc.validate(objLatLon,callback) None This method will return validated object objLatLon. The result gives callback function as the result object.
  • objLatLon - This is a instance of LatLon class.
  • callback - This recieves a result object.
txtester.gpscoordcalc.calculate(objLatLon,callback) None This method will return instance of Coordinates class. The result gives callback function as the result object.
  • objLatLon - This is a instance of LatLon class.
  • callback - This recieves a result object.
txtester.gpscoordcalc.getLatLon(String,callback) None This method will return instance of LatLon class. The result gives callback function as the result object.
  • String - Coordinates in an arbitrary WGS84 conformation.
  • callback - This recieves a result object.

Class LatLon

This class has no methods. Instances of this class are used as interface.

Constructor

Constructor Description
txtester.gpscoordcalc.LatLon(lat: Object, lon: Object) Creates a LatLon object. The latitude and longitude must be the instances of the same class.

Properties

Property Type Description
className String "LatLon" This property use only for reading.
lat Object CoordDec or CoordDM or CoordDMS
lon Object CoordDec or CoordDM or CoordDMS

Class CoordDec

This class has no methods. Instances of this class are used as interface. This class represents a coordinates. (lat/lon format: ddd.dddddd°)

Constructor

Constructor Description
txtester.gpscoordcalc.CoordDec ( latlonChar:String, ddd:Integer, dddddd:Integer) Creates a CoordDec object.

Properties

Property Type Description
className String "CoordDec" This property use only for reading.
latlonChar String Valid values are: "", "-".
ddd Integer Valid range: latitude from 0 to 90 degrees, longitude from 0 to 180 degrees.
dddddd Integer This property represents the value of the number after the decimal point. Sample: For the latitude 49.354 are correct values ddd=49, dddddd=354000. The properties ddd and dddddd together represents a decimal number.

Class CoordDM

This class has no methods. Instances of this class are used as interface. This class represents a coordinates. (lat/lon format: ddd° mm.mmm')

Constructor

Constructor Description
txtester.gpscoordcalc.CoordDM ( latlonChar:String, ddd:Integer, mm:Integer, mmm:Integer) Creates a CoordDM object.

Properties

Property Type Description
className String "CoordDM" This property use only for reading.
latlonChar String Valid values for the latitude are: "N", "S". Valid values for the longitude are: "E", "W". This values are case sensitivy.
ddd Integer Valid range: latitude from 0 to 90 degrees, longitude from 0 to 180 degrees.
mm Integer Valid range: from 0 to 59 minutes.
mmm Integer This property represents the value of the number after the decimal point. Sample: For the latitude 49°21.240' are correct values ddd=49, mm=21, mmm=240. The properties mm and mmm together represents a decimal number.

Class CoordDMS

This class has no methods. Instances of this class are used as interface. This class represents a coordinates. (lat/lon format: ddd° mm' ss.ssss")

Constructor

Constructor Description
txtester.gpscoordcalc.CoordDMS ( latlonChar:String, ddd:Integer, mm:Integer, ss:Integer, ssss:Integer) Creates a CoordDMS object.

Properties

Property Type Description
className String "CoordDMS" This property use only for reading.
latlonChar String Valid values for the latitude are: "N", "S". Valid values for the longitude are: "E", "W". This values are case sensitivy.
ddd Integer Valid range: latitude from 0 to 90 degrees, longitude from 0 to 180 degrees.
mm Integer Valid range: from 0 to 59 minutes.
ss Integer Valid range: from 0 to 59 seconds.
ssss Integer This property represents the value of the number after the decimal point. Sample: For the latitude 49° 21' 14.3999" are correct values ddd=49, mm=21, ss=14, ssss=3999. The properties ss and ssss together represents a decimal number.

Class Coordinates

This class has no methods. Instances of this class are used as interface.

Constructor

Constructor Description
txtester.gpscoordcalc.Coordinates(LatLonDec: Object, LatLonDM: Object, LatLonDMS: Object ) Creates a Coordinates object.

Properties

Property Type Description
className String "Coordinates" This property use only for reading.
LatLonDec Object LatLon, where the properties Latlon.lat and LatLon.lon contains instances of the CoordDec class.
LatLonDM Object LatLon, where the properties Latlon.lat and LatLon.lon contains instances of the CoordDM class.
LatLonDMS Object LatLon, where the properties Latlon.lat and LatLon.lon contains instances of the CoordDMS class.

Result Objects

validate Result
calculate Result
getLatLon Result

Examples

Validate LatLon object
//create LatLon
var objLat=new txtester.gpscoordcalc.CoordDM("N",48,58,469);
var objLon=new txtester.gpscoordcalc.CoordDM("E",14,28,459);
var objLatLon=new txtester.gpscoordcalc.LatLon(objLat,objLon);

//validate
txtester.gpscoordcalc.validate(objLatLon,function(result){
  if(!result.error){
    //validated the LatLon object
    objLatLon=result.LatLon;
  }
});
Calculate coordinates
//create LatLon
var objLat=new txtester.gpscoordcalc.CoordDM("N",48,58,469);
var objLon=new txtester.gpscoordcalc.CoordDM("E",14,28,459);
var objLatLon=new txtester.gpscoordcalc.LatLon(objLat,objLon);

//calculate
txtester.gpscoordcalc.calculate(objLatLon,function(result){
  if(!result.error){
    var objCoordinates=result.Coordinates;
    with(objCoordinates.LatLonDec){
      alert("latitude: " + lat.ddd + "." + lat.dddddd
      + "\nlongitude: " + lon.ddd + "." + lon.dddddd);
    }
  }
  else{
    alert("Calculate, error: "+result.error.code);
  }
});
Getting LatLon object
This method tries to discern a coordinates from the text.
//coordinates in the String
var gpsText="  n48 58,469 -14 28.459   "

//getLatLon
txtester.gpscoordcalc.getLatLon(gpsText,function(result){
  if(!result.error){
    var objLatLon=result.LatLon;
  }
  else{
    alert("txtester.gpscoordcalc.getLatLon: result.error=" + result.error.code);
    return;	
  }
});

Full Code - Example 1
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://www.txtester.com/jsapi/gpscoordcalc-1-1.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
function fCalculate(){
var s, objLatLon, objCoordinates;
var gpsText=document.getElementById("txtGPS").value;

//getLatLon
txtester.gpscoordcalc.getLatLon(gpsText,function(result){
  if(!result.error){
    objLatLon=result.LatLon;
  }
  else{
    alert("txtester.gpscoordcalc.getLatLon: result.error=" + result.error.code);
    return;	
  }
});

//validate
txtester.gpscoordcalc.validate(objLatLon,function(result){
  if(!result.error){
    objLatLon=result.LatLon;
  }
  else{
    alert("Validate, error: "+result.error.code);
    return;
  }
});

//calculate
txtester.gpscoordcalc.calculate(objLatLon,function(result){
  if(!result.error){
    objCoordinates=result.Coordinates;
  }
  else{
    alert("Calculate, error: "+result.error.code);
    return;
  }
});

//display coordinates
with(objCoordinates.LatLonDec){
  s=lat.latlonChar + lat.ddd + "." + lat.dddddd;
  s+=" " + lon.latlonChar + lon.ddd + "." + lon.dddddd;
}
with(objCoordinates.LatLonDM){
  s+="<br />" + lat.latlonChar + lat.ddd + "° " + lat.mm + "." + lat.mmm + "'";
  s+=" " + lon.latlonChar + lon.ddd + "° " + lon.mm + "." + lon.mmm + "'";
}
with(objCoordinates.LatLonDMS){
  s+="<br />" + lat.latlonChar + lat.ddd +  "° " + lat.mm + "' " + lat.ss + "." + lat.ssss + "''";
  s+=" " + lon.latlonChar + lon.ddd + "° " + lon.mm + "' " + lon.ss + "." + lon.ssss + "''";
}
document.getElementById("coords").innerHTML= s;
}
-->
</script>
</head>
<body>
<div>
<input type="text" id="txtGPS" style="width:250px;" value="  +48 37 58.469 w14 21 28,459   " />
<input type="button" id="cmdCalc" onclick="fCalculate();" value="OK" />
</div>
<br />
<div id="coords">...</div>
</body>
</html>
View example (full_code_example1.htm)
Full Code - Example 2
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://www.txtester.com/jsapi/gpscoordcalc-1-1.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
function fCalculate(){
var s, objLatLon, objCoordinates;
var gpsText=document.getElementById("txtGPS").value;

txtester.gpscoordcalc.getLatLon(gpsText,function(result){
  if(!result.error){
    objLatLon=result.LatLon;
    txtester.gpscoordcalc.validate(objLatLon,function(result){
      if(!result.error){
        objLatLon=result.LatLon;
        txtester.gpscoordcalc.calculate(objLatLon,function(result){
          if(!result.error){
            objCoordinates=result.Coordinates;
            with(objCoordinates.LatLonDec){
	      s=lat.latlonChar + lat.ddd + "." + lat.dddddd;
    	      s+=" " + lon.latlonChar + lon.ddd + "." + lon.dddddd;
            }
            with(objCoordinates.LatLonDM){
	      s+="<br />" + lat.latlonChar + lat.ddd + "° " + lat.mm + "." + lat.mmm + "'";
    	      s+=" " + lon.latlonChar + lon.ddd + "° " + lon.mm + "." + lon.mmm + "'";
            }
            with(objCoordinates.LatLonDMS){
	      s+="<br />" + lat.latlonChar + lat.ddd +  "° " + lat.mm + "' " + lat.ss + "." + lat.ssss + "''";
    	      s+=" " + lon.latlonChar + lon.ddd + "° " + lon.mm + "' " + lon.ss + "." + lon.ssss + "''";
            }
            document.getElementById("coords").innerHTML= s;
          }
          else{
            alert("Calculate, error: "+result.error.code);
          }
        });
      }
      else{
        alert("Validate, error: "+result.error.code);
      }
    });
  }
  else{
    alert("txtester.gpscoordcalc.getLatLon: result.error=" + result.error.code);
    return;	
  }
});
}
-->
</script>
</head>
<body>
<div>
<input type="text" id="txtGPS" style="width:250px;" value="  n48 58,469 -14 28.459   " />
<input type="button" id="cmdCalc" onclick="fCalculate();" value="OK" />
</div>
<br />
<div id="coords">...</div>
</body>
</html>
View example (full_code_example2.htm)