GPS Coord Calc API (version 1.2)
Global Methods
| Method |
Return Type |
Description |
txtester.gpscoordcalc.validate(LatLon,callback) |
None |
This method will return validated object objLatLon. The result gives callback function as the result object.
- LatLon - This is a instance of LatLon class.
- callback - This recieves a result object.
|
txtester.gpscoordcalc.calculate(LatLon,callback) |
None |
This method will return instance of Coordinates class. The result gives callback function as the result object.
- LatLon - 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.
|
txtester.gpscoordcalc.getMapUrl(Domain,Coordinates,
MapType,Zoom,callback) |
None |
This method will return the URL string of online map to desired location. The result gives callback function as the result object.
- Domain - This specifies the domain with an online map, which is to be generated URL. See the Domain enum.
- Coordinates - Coordinates the desired point. This is instance of Coordinates class.
- MapType - This specifies the type of map. See the MapType enum.
- Zoom - Integer. The minimum zoom level is number 1. The maximum zoom level is dependent on the type of map of the selected domain.
- 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
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, deg:Number)
|
Creates a CoordDec object.
|
Properties
| Property |
Type |
Description |
className |
String "CoordDec" |
This property use only for reading. |
latlonChar |
String |
Valid values are: "", "-". |
deg |
Number |
Valid range: latitude from 0 to 90 degrees, longitude from 0 to 180 degrees. |
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, deg:Integer, min:Number)
|
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. |
deg |
Integer |
Valid range: latitude from 0 to 90 degrees, longitude from 0 to 180 degrees. |
min |
Number |
Valid range: from 0 to 59,999 minutes. |
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, deg:Integer, min:Integer, sec:Number)
|
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. |
deg |
Integer |
Valid range: latitude from 0 to 90 degrees, longitude from 0 to 180 degrees. |
min |
Integer |
Valid range: from 0 to 59 minutes. |
sec |
Number |
Valid range: from 0 to 59,9999 seconds. |
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
result
-
error?
LatLon
The validated object of LatLon class.
calculate Result
getLatLon Result
result
-
error?
LatLon
The object of LatLon class.
getMapUrl Result
result
-
error?
url
Url string of online map.
Enums
ErrorCode enum
This enum is used in the
Result objects as the
result.error.code parameter.
txtester.gpscoordcalc.ErrorCode={
NAO_LATLON:1, //Not the LatLon object.
LAT_CHAR:18, //Latitude - Invalid value of the 'char' parameter.
LON_CHAR:19, //Longitude - Invalid value of the 'char' parameter.
LAT_OVERFLOWE:20, //Latitude value outside the valid range.
LON_OVERFLOWE:21, //Longitude value outside the valid range.
LAT_DEG:22, //Latitude - Invalid value of the 'deg' parameter.
LON_DEG:23, //Longitude - Invalid value of the 'deg' parameter.
LAT_MIN:24, //Latitude - Invalid value of the 'min' parameter.
LON_MIN:25, //Longitude - Invalid value of the 'min' parameter.
LAT_SEC:26, //Latitude - Invalid value of the 'sec' parameter.
LON_SEC:27, //Longitude - Invalid value of the 'sec' parameter.
GETLATLON_NO_COORDINATES: 28, // The global function getLatLon
INVALID_DOMAIN: 50 //Invalid domain name.
}
Domain enum
This enum is used in the method
txtester.gpscoordcalc.getMapUrl() as the
Domain parameter.
txtester.gpscoordcalc.Domain={
GOOGLE_COM : 'google.com', //Supported 'MapType' values: HYBRID, ROADMAP, SATELLITE, TERRAIN
MAPY_CZ : 'mapy.cz', //Supported 'MapType' values: BASIC, PHOTO, TOURIST
AMAPY_CZ : 'amapy.cz', //Supported 'MapType' values: BASIC
MAPQUEST_COM : 'mapquest.com', //Supported 'MapType' values: AERIAL, HYBRID, STREET
OPENSTREETMAP_ORG : 'openstreetmap.org', //Supported 'MapType' values: BASIC
YAHOO_COM : 'yahoo.com' //Supported 'MapType' values: HYBRID, MAP, SATELLITE
}
MapType enum
This enum is used in the method
txtester.gpscoordcalc.getMapUrl() as the
MapType parameter.
txtester.gpscoordcalc.MapType={
BASIC : 'ba',
HYBRID : 'hy',
ROADMAP : 'ro',
SATELLITE : 'sa',
TERRAIN : 'te',
MAP : 'mp',
TOURIST : 'to',
PHOTO: 'ph',
AERIAL: 'ae',
STREET : 'st'
}
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.deg + "\nlongitude: " + lon.deg);
}
}
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-2.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.deg;
s+=" " + lon.latlonChar + lon.deg;
}
with(objCoordinates.LatLonDM){
s+="<br />" + lat.latlonChar + lat.deg + "° " + lat.min + "'";
s+=" " + lon.latlonChar + lon.deg + "° " + lon.min + "'";
}
with(objCoordinates.LatLonDMS){
s+="<br />" + lat.latlonChar + lat.deg + "° " + lat.min + "' " + lat.sec + "''";
s+=" " + lon.latlonChar + lon.deg + "° " + lon.min + "' " + lon.sec + "''";
}
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>
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-2.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.deg;
s+=" " + lon.latlonChar + lon.deg;
}
with(objCoordinates.LatLonDM){
s+="<br />" + lat.latlonChar + lat.deg + "° " + lat.min + "'";
s+=" " + lon.latlonChar + lon.deg + "° " + lon.min + "'";
}
with(objCoordinates.LatLonDMS){
s+="<br />" + lat.latlonChar + lat.deg + "° " + lat.min + "' " + lat.sec + "''";
s+=" " + lon.latlonChar + lon.deg + "° " + lon.min + "' " + lon.sec + "''";
}
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>