Added wrt files, prior to converting into Qt/C++.
[ptas] / wrt / misc / rss / preview / script / lib / sapi / Location.js
diff --git a/wrt/misc/rss/preview/script/lib/sapi/Location.js b/wrt/misc/rss/preview/script/lib/sapi/Location.js
new file mode 100644 (file)
index 0000000..99e1886
--- /dev/null
@@ -0,0 +1,523 @@
+/**\r
+ * Location.js\r
+ * \r
+ * Nokia Web Runtime Service API emulation \r
+ * WRT v1.1\r
+ * \r
+ * Copyright 2009 Nokia Corporation. All rights reserved.\r
+*/\r
+\r
\r
+(function(){\r
+       \r
+       var provider = 'Service.Location',\r
+               Interface = 'ILocation';\r
+\r
+       /**\r
+        * Landmark service\r
+        */\r
+       var LocationService = function(){\r
+               this.GetLocation                        = __GetLocation;\r
+               this.Trace                                      = __Trace;\r
+               this.Calculate                          = __Calculate;\r
+               this.CancelNotification         = __CancelNotification;         \r
+       }\r
+\r
+       device.implementation.extend(provider, Interface, new LocationService() );\r
+\r
+\r
+       /******************************************************/        \r
+       /******************************************************/        \r
+       /******************************************************/        \r
+\r
+       var     context = device.implementation.context,\r
+               _t = context._t,\r
+               method = '',\r
+               result = false,\r
+               DBase = null;\r
+\r
+\r
+       var transactionIds = new Array();\r
+       var tTransactionId = -1;\r
+       var isTraceInProgress = false;\r
+       var criteriaTrace;\r
+       var callbackTrace;\r
+\r
+       /**\r
+        * Landmarks: GetLocation\r
+        * @param {Object} criteria\r
+        */\r
+       function __GetLocation(criteria, callback, flag){       \r
+               method = "GetLocation";\r
+               //      Async call\r
+               flag = flag || false;\r
+\r
+               if (!criteria) {\r
+                       criteria = new Object();\r
+               }       \r
+               \r
+               if(typeof criteria.LocationInformationClass == "undefined")\r
+                       criteria.LocationInformationClass = "BasicLocationInformation"; // Default value of LocationInformationClass is "BasicLocationInformation" if not provided\r
+\r
+               var result = validateArgument('GetLocation',criteria);\r
+               if(result.ErrorCode != 0)\r
+                       return result;\r
+               \r
+               if (typeof callback == 'function') {\r
+                       \r
+                       var retVal = context.callAsync(this, arguments.callee, criteria, callback,true);\r
+                       transactionIds.push(retVal.TransactionID);  // all transaction ids are pushed on this variable, because CancelNotification function of SAPI doesn't take TransactioID as input\r
+                       return retVal;\r
+               }\r
+               \r
+               if(flag)\r
+               {\r
+                       transactionIds.shift();  // Remove oldest TransactionID(FIFO) (Async call)\r
+               }\r
+               \r
+               DBase = context.getData(provider);\r
+               var returnValue = DBase[criteria.LocationInformationClass];\r
+               locationNotify(criteria.Updateoptions);\r
+               return context.Result(returnValue);\r
+       }\r
+       \r
+       /**\r
+        * Location: Trace\r
+        * @param {Object} criteria\r
+        * @param {Function} callback function for async call\r
+        */\r
+       function __Trace(criteria, callback){\r
+               method = "Trace";\r
+\r
+               if (!criteria) {\r
+                       criteria = new Object();\r
+               }       \r
+               \r
+               if(typeof criteria.LocationInformationClass == "undefined")\r
+                       criteria.LocationInformationClass = "BasicLocationInformation"; // Default value of LocationInformationClass is "BasicLocationInformation" if not provided\r
+\r
+               if (typeof callback != 'function') { // callback should be valid function\r
+                       return error(device.implementation.ERR_SERVICE_NOT_SUPPORTED,msg.msgCommandNotFound); \r
+               }\r
+               \r
+               var result = validateArgument('Trace',criteria);\r
+               if(result.ErrorCode != 0)\r
+                       return result;\r
+               \r
+               criteriaTrace = criteria;\r
+               callbackTrace = callback;\r
+               isTraceInProgress = true;\r
+               locationNotify(criteria.Updateoptions);\r
+\r
+               return traceCall(criteria,callback);\r
+       }\r
+\r
+       /**\r
+        * Location: Calculate\r
+        * @param {Object} criteria\r
+        */\r
+       function __Calculate(criteria){\r
+               method = "Calculate";\r
+               if(!criteria || !criteria.MathRequest)\r
+                       return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgCalcMissingMathReq);\r
+                       \r
+               if(typeof criteria.MathRequest != "string" || (criteria.MathRequest != "FindDistance" && criteria.MathRequest != "FindBearingTo" && criteria.MathRequest != "MoveCoordinates")) // Error check for wrong MathRequest criteria\r
+                       return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgCalcWrongTypeMathReq);\r
+                       \r
+               if(typeof criteria.DistanceParamSource != "object" || (typeof criteria.DistanceParamSource.Latitude != "number" || typeof criteria.DistanceParamSource.Longitude != "number" || typeof criteria.DistanceParamSource.Altitude != "number"))\r
+                       return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgCalcMissingArgLocCord);\r
+\r
+               if(criteria.MathRequest == "FindDistance" || criteria.MathRequest == "FindBearingTo")\r
+               {\r
+                       if(typeof criteria.DistanceParamSource != "object" || (typeof criteria.DistanceParamDestination.Latitude != "number" || typeof criteria.DistanceParamDestination.Longitude != "number" || typeof criteria.DistanceParamDestination.Altitude != "number"))\r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgCalcMissingArgLocCord);\r
+                       if (criteria.MathRequest == "FindDistance") {\r
+                               var dist = LatLon.distHaversine(criteria.DistanceParamDestination.Latitude, criteria.DistanceParamDestination.Longitude, criteria.DistanceParamSource.Latitude, criteria.DistanceParamSource.Longitude)*1000;\r
+                               if (typeof criteria.DistanceParamDestination.Altitude == "number" && typeof criteria.DistanceParamSource.Altitude == "number") {\r
+                                       var delta = criteria.DistanceParamDestination.Altitude - criteria.DistanceParamSource.Altitude\r
+                                       dist = Math.sqrt(dist * dist + delta * delta);\r
+                               }\r
+                               return context.Result(dist);\r
+                       }\r
+                       else if (criteria.MathRequest == "FindBearingTo"){\r
+                               var bearing = LatLon.bearing( criteria.DistanceParamSource.Latitude, criteria.DistanceParamSource.Longitude,criteria.DistanceParamDestination.Latitude, criteria.DistanceParamDestination.Longitude);\r
+                               return context.Result(bearing);                         \r
+                       }\r
+               }\r
+               else if(criteria.MathRequest == "MoveCoordinates"){\r
+\r
+                       if(typeof criteria.MoveByThisDistance == "undefined")\r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgCalcMissingArgMoveDist);\r
+                       \r
+                       if(typeof criteria.MoveByThisBearing == "undefined")\r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgCalcMissingArgMoveBear);\r
+                       \r
+\r
+                       if(typeof criteria.MoveByThisDistance != "number")\r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgCalcWrongTypeMoveDist);\r
+                       \r
+                       if(typeof criteria.MoveByThisBearing != "number")\r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgCalcWrongTypeMoveBear);\r
+                       \r
+                       var latLon = new LatLon(criteria.DistanceParamSource.Latitude, criteria.DistanceParamSource.Longitude);\r
+                       var dlatLon = latLon.destPoint(criteria.MoveByThisBearing, criteria.MoveByThisDistance/1000);\r
+                       var retVal = new Object();\r
+                       retVal.Longitude = dlatLon.lon;\r
+                       retVal.Latitude = dlatLon.lat;\r
+                       retVal.Altitude = criteria.DistanceParamSource.Altitude;\r
+                       return context.Result(retVal);\r
+               }\r
+       }\r
+                       \r
+       /**\r
+        * Location: CancelNotification\r
+        * @param {Object} criteria\r
+        */\r
+       function __CancelNotification(criteria){\r
+               method = "Cancel";\r
+               if(!criteria)\r
+                               return error(device.implementation.ERR_MISSING_ARGUMENT,msg.msgCancelMissingType);\r
+               \r
+               var arr = new Array();\r
+               var i = 0;\r
+               var key\r
+               for(key in criteria);\r
+                       arr[i++] = key;\r
+\r
+               if(!criteria.CancelRequestType && arr.length)\r
+                               return error(device.implementation.ERR_NOT_FOUND,msg.msgCancelMissingType);\r
+               \r
+               if(criteria.CancelRequestType != "GetLocCancel" && criteria.CancelRequestType != "TraceCancel")\r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgCancelWrongType);\r
+               \r
+               if (criteria.CancelRequestType == "GetLocCancel") {\r
+                       for (var i = 0; i < transactionIds.length; i++) {\r
+                               clearTimeout(transactionIds[i])\r
+                       }\r
+               }\r
+               \r
+               if (criteria.CancelRequestType == "TraceCancel")\r
+               {\r
+                       isTraceInProgress = false;\r
+                       tTransactionId = -1;\r
+               }\r
+               return context.ErrorResult(device.implementation.ERR_SUCCESS);\r
+       }\r
+               \r
+\r
+\r
+       \r
+       /*******************************\r
+        * helper functions\r
+        *******************************/\r
+\r
+       /**\r
+        * Location: traceCall\r
+        * @param {} \r
+        * This function emulates repetitive trace calls,It calls specified callback function after every UpdateInterval untill \r
+        * CancelNotification is called\r
+        */\r
+       function traceCall(){\r
+               var tid = setTimeout(function(){\r
+               if(!isTraceInProgress)\r
+                       return;\r
+                       \r
+               DBase = context.getData(provider);\r
+               var returnValue = DBase[criteriaTrace.LocationInformationClass];\r
+               var result,\r
+                       eventCode = {completed:2, error:4, progress:9},\r
+               code = eventCode.completed;\r
+\r
+               callbackTrace(tTransactionId,code,context.Result(returnValue,0));\r
+               traceCall();\r
+               }, criteriaTrace.Updateoptions.UpdateInterval/1000);\r
+               if(tTransactionId == -1)\r
+                       tTransactionId = tid;\r
+               return context.AsyncResult(tTransactionId);\r
+       }\r
+\r
+       /**\r
+        * Location: validateArgument\r
+        * @param {string,object} callingMethod and criteria\r
+        * Validates arguments\r
+        */\r
+       function validateArgument(fun,criteria)\r
+       {\r
+               method = fun;\r
+               if(typeof criteria.Updateoptions != "undefined")\r
+               {\r
+                       if(typeof criteria.Updateoptions != "object") // Checking for error in UpdateOptions criteria\r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgGetLocationBadArg);\r
+                       \r
+                       if(typeof criteria.Updateoptions.UpdateInterval != "undefined" && typeof criteria.Updateoptions.UpdateInterval != "number")\r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgGetLocationWrongType);\r
+                       \r
+                       if(typeof criteria.Updateoptions.UpdateTimeOut != "undefined" && typeof criteria.Updateoptions.UpdateTimeOut != "number")       \r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgGetLocationWrongType);\r
+\r
+                       if(typeof criteria.Updateoptions.UpdateMaxAge != "undefined" && typeof criteria.Updateoptions.UpdateMaxAge != "number") \r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgGetLocationWrongType);\r
+\r
+                       if(typeof criteria.Updateoptions.PartialUpdates != "undefined" && typeof criteria.Updateoptions.PartialUpdates != "boolean")    \r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgGetLocationWrongType);\r
+\r
+                       if((typeof criteria.Updateoptions.UpdateInterval != "undefined" && criteria.Updateoptions.UpdateInterval  < 0) || \r
+                                       (typeof criteria.Updateoptions.UpdateTimeOut != "undefined" && criteria.Updateoptions.UpdateTimeOut  < 0) ||\r
+                                       (typeof criteria.Updateoptions.UpdateMaxAge != "undefined" && criteria.Updateoptions.UpdateMaxAge  < 0))\r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgGetLocationNegInt);\r
+\r
+                       if(typeof criteria.Updateoptions.UpdateTimeOut != "undefined" && typeof criteria.Updateoptions.UpdateInterval != "undefined" && criteria.Updateoptions.UpdateInterval > criteria.Updateoptions.UpdateTimeOut)\r
+                       {\r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgNone);\r
+                       }\r
+\r
+                       /*if((typeof criteria.Updateoptions.UpdateTimeOut != "undefined" && criteria.Updateoptions.UpdateTimeOut <= 1000000))// || (typeof criteria.Updateoptions.UpdateInterval != "undefined" && criteria.Updateoptions.UpdateInterval <= 1000000))\r
+                       {\r
+                               return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgNone);\r
+                       }*/                             \r
+               }\r
+\r
+               if(typeof criteria.LocationInformationClass != "undefined" && criteria.LocationInformationClass != "BasicLocationInformation" && criteria.LocationInformationClass != "GenericLocationInfo") // checking for errors in LocationInformationClass criteria\r
+                       return error(device.implementation.ERR_BAD_ARGUMENT_TYPE,msg.msgGetLocationWrongCat);\r
+               \r
+               if (/^Trace$/i.test(fun)&&(!criteria.Updateoptions || typeof criteria.Updateoptions.UpdateInterval == "undefined")) {\r
+                       if(!criteria.Updateoptions)\r
+                       {\r
+                               criteria.Updateoptions = new Object();\r
+                       }\r
+                       criteria.Updateoptions.UpdateInterval = 1000000;  // Emulation only!! for convenience UpdateInterval is set to 1 second is not specified or if it less than 1 second\r
+                       context.notify("Using default UpdateInterval(1000000 micro seconds)"); \r
+               }\r
+               \r
+               return context.ErrorResult(device.implementation.ERR_SUCCESS, "");\r
+               \r
+       }\r
+\r
+       /**\r
+        * Location: error\r
+        * @param {number,string} ErrorCode and ErrorString\r
+        * Replaces Error String with method name\r
+        */\r
+       function error(code, msg /*, args...*/){\r
+\r
+               var args = ['location',method].concat([].slice.call(arguments,2));\r
+               msg = msg ? _t().arg.apply(msg,args) : undefined;\r
+               return context.ErrorResult(code, msg);\r
+       }\r
+       \r
+       function locationNotify(updateoptions) {\r
+               if(!updateoptions)\r
+                       return;\r
+               if(typeof updateoptions.UpdateTimeOut != "undefined")\r
+                       context.notify(_t("%s:: %s : Updateoptions.UpdateTimeOut not implemented in preview").arg(provider, method));\r
+\r
+               if(typeof updateoptions.UpdateMaxAge != "undefined")\r
+                       context.notify(_t("%s:: %s : Updateoptions.UpdateMaxAge not implemented in preview").arg(provider, method));\r
+\r
+               if(typeof updateoptions.PartialUpdates != "undefined")\r
+                       context.notify(_t("%s:: %s : Updateoptions.PartialUpdates not implemented in preview").arg(provider, method));\r
+       }\r
+\r
+       /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
+       /*  Latitude/longitude spherical geodesy formulae & scripts (c) Chris Veness 2002-2009            */\r
+       /*      http://www.movable-type.co.uk/scripts/latlong.html                                                                                        */  \r
+       /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
+       \r
+       /*\r
+        * Use Haversine formula to Calculate distance (in km) between two points specified by \r
+        * latitude/longitude (in numeric degrees)\r
+        *\r
+        * example usage from form:\r
+        *   result.value = LatLon.distHaversine(lat1.value.parseDeg(), long1.value.parseDeg(), \r
+        *                                       lat2.value.parseDeg(), long2.value.parseDeg());\r
+        * where lat1, long1, lat2, long2, and result are form fields\r
+        */\r
+       \r
+       \r
+       LatLon.distHaversine = function(lat1, lon1, lat2, lon2) {\r
+         var R = 6371; // earth's mean radius in km\r
+         var dLat = toRad(lat2-lat1);\r
+         var dLon = toRad(lon2-lon1);\r
+         lat1 = toRad(lat1), lat2 = toRad(lat2);\r
+       \r
+         var a = Math.sin(dLat/2) * Math.sin(dLat/2) +\r
+                 Math.cos(lat1) * Math.cos(lat2) * \r
+                 Math.sin(dLon/2) * Math.sin(dLon/2);\r
+         var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));\r
+         var d = R * c;\r
+         return d;\r
+       }\r
+       \r
+       \r
+       /*\r
+        * ditto using Law of Cosines\r
+        */\r
+       LatLon.distCosineLaw = function(lat1, lon1, lat2, lon2) {\r
+         var R = 6371; // earth's mean radius in km\r
+         var d = Math.acos(Math.sin(toRad(lat1))*Math.sin(toRad(lat2)) +\r
+                           Math.cos(toRad(lat1))*Math.cos(toRad(lat2))*Math.cos(toRad(lon2-lon1))) * R;\r
+         return d;\r
+       }\r
+       \r
+       \r
+       /*\r
+        * calculate (initial) bearing between two points\r
+        *   see http://williams.best.vwh.net/avform.htm#Crs\r
+        */\r
+       LatLon.bearing = function(lat1, lon1, lat2, lon2) {\r
+         lat1 = toRad(lat1); lat2 = toRad(lat2);\r
+         var dLon = toRad(lon2-lon1);\r
+\r
+         var y = Math.sin(dLon) * Math.cos(lat2);\r
+         var x = Math.cos(lat1)*Math.sin(lat2) -\r
+                 Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);\r
+         return toBrng(Math.atan2(y, x));\r
+       }\r
+       \r
+       \r
+       /*\r
+        * calculate destination point given start point, initial bearing (deg) and distance (km)\r
+        *   see http://williams.best.vwh.net/avform.htm#LL\r
+        */\r
+       LatLon.prototype.destPoint = function(brng, d) {\r
+         var R = 6371; // earth's mean radius in km\r
+         var lat1 = toRad(this.lat), lon1 = toRad(this.lon);\r
+         brng = toRad(brng);\r
+       \r
+         var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) + \r
+                               Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );\r
+         var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1), \r
+                                      Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));\r
+         lon2 = (lon2+Math.PI)%(2*Math.PI) - Math.PI;  // normalise to -180...+180\r
+       \r
+         if (isNaN(lat2) || isNaN(lon2)) return null;\r
+         return new LatLon(toDeg(lat2), toDeg(lon2));\r
+       }\r
+       \r
+       \r
+       /*\r
+        * construct a LatLon object: arguments in numeric degrees\r
+        *\r
+        * note all LatLong methods expect & return numeric degrees (for lat/long & for bearings)\r
+        */\r
+       function LatLon(lat, lon) {\r
+         this.lat = lat;\r
+         this.lon = lon;\r
+       }\r
+       \r
+       \r
+       /*\r
+        * represent point {lat, lon} in standard representation\r
+        */\r
+       LatLon.prototype.toString = function() {\r
+         return this.lat.toLat() + ', ' + this.lon.toLon();\r
+       }\r
+       \r
+       /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
+       \r
+       // extend String object with method for parsing degrees or lat/long values to numeric degrees\r
+       //\r
+       // this is very flexible on formats, allowing signed decimal degrees, or deg-min-sec suffixed by \r
+       // compass direction (NSEW). A variety of separators are accepted (eg 3º 37' 09"W) or fixed-width \r
+       // format without separators (eg 0033709W). Seconds and minutes may be omitted. (Minimal validation \r
+       // is done).\r
+       \r
+       function parseDeg (str) {\r
+         if (!isNaN(str)) return Number(str);                 // signed decimal degrees without NSEW\r
+       \r
+         var degLL = str.replace(/^-/,'').replace(/[NSEW]/i,'');  // strip off any sign or compass dir'n\r
+         var dms = degLL.split(/[^0-9.]+/);                     // split out separate d/m/s\r
+         for (var i in dms) if (dms[i]=='') dms.splice(i,1);    // remove empty elements (see note below)\r
+         switch (dms.length) {                                  // convert to decimal degrees...\r
+           case 3:                                              // interpret 3-part result as d/m/s\r
+             var deg = dms[0]/1 + dms[1]/60 + dms[2]/3600; break;\r
+           case 2:                                              // interpret 2-part result as d/m\r
+             var deg = dms[0]/1 + dms[1]/60; break;\r
+           case 1:                                              // decimal or non-separated dddmmss\r
+             if (/[NS]/i.test(str)) degLL = '0' + degLL;       // - normalise N/S to 3-digit degrees\r
+             var deg = dms[0].slice(0,3)/1 + dms[0].slice(3,5)/60 + dms[0].slice(5)/3600; break;\r
+           default: return NaN;\r
+         }\r
+         if (/^-/.test(str) || /[WS]/i.test(str)) deg = -deg; // take '-', west and south as -ve\r
+         return deg;\r
+       }\r
+       // note: whitespace at start/end will split() into empty elements (except in IE)\r
+       \r
+       \r
+       /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
+       \r
+       // extend Number object with methods for converting degrees/radians\r
+       \r
+       function toRad (deg) {  // convert degrees to radians\r
+         return deg * Math.PI / 180;\r
+       }\r
+       \r
+       function toDeg (rad) {  // convert radians to degrees (signed)\r
+         return rad * 180 / Math.PI;\r
+       }\r
+       \r
+       function toBrng (rad) {  // convert radians to degrees (as bearing: 0...360)\r
+         return (toDeg(rad)+360) % 360;\r
+       }\r
+       \r
+       \r
+       /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
+       \r
+       // extend Number object with methods for presenting bearings & lat/longs\r
+       \r
+       function toDMS (num) {  // convert numeric degrees to deg/min/sec\r
+         var d = Math.abs(num);  // (unsigned result ready for appending compass dir'n)\r
+         d += 1/7200;  // add ½ second for rounding\r
+         var deg = Math.floor(d);\r
+         var min = Math.floor((d-deg)*60);\r
+         var sec = Math.floor((d-deg-min/60)*3600);\r
+         // add leading zeros if required\r
+         if (deg<100) deg = '0' + deg; if (deg<10) deg = '0' + deg;\r
+         if (min<10) min = '0' + min;\r
+         if (sec<10) sec = '0' + sec;\r
+         return deg + '\u00B0' + min + '\u2032' + sec + '\u2033';\r
+       }\r
+       \r
+       function toLat (deg) {  // convert numeric degrees to deg/min/sec latitude\r
+         return toDMS(deg).slice(1) + (deg<0 ? 'S' : 'N');  // knock off initial '0' for lat!\r
+       }\r
+       \r
+       function toLon (deg) {  // convert numeric degrees to deg/min/sec longitude\r
+         return toDMS(deg) + (deg>0 ? 'E' : 'W');\r
+       }\r
+       \r
+       function toPrecision (num,fig) {  // override toPrecision method with one which displays \r
+         if (num == 0) return 0;                      // trailing zeros in place of exponential notation\r
+         var scale = Math.ceil(Math.log(num)*Math.LOG10E);\r
+         var mult = Math.pow(10, fig-scale);\r
+         return Math.round(num*mult)/mult;\r
+       }\r
+\r
+\r
+       /** \r
+        * error messages\r
+        * order of %s args: Service name, method name, parameter name \r
+        */\r
+       var msg = {\r
+               msgCommandNotFound                      : '%s : Command Not found',\r
+               msgGetLocationWrongCat          : '%s : %s : wrong category info should be BasicLocationInformation/GenericLocationInfo ',\r
+               msgGetLocationBadArg            : '%s : %s : BadArgument - Updateoptions',\r
+               msgGetLocationNegInt            : '%s : %s : Negative Time Interval',\r
+               msgGetLocationWrongType         : '%s : %s : UpdateOptions Type mismatch',\r
+               msgTraceWrongCat                        : '%s : %s : Invalid LocationInformationClass',\r
+               msgCalcMissingMathReq           : '%s : %s : Missing argument - MathRequest',\r
+               msgCalcWrongTypeMathReq         : '%s : %s : Wrong argument - MathRequest',\r
+               msgCalcMissingArgLocCord        : '%s : %s : Missing argument - locationcoordinate',\r
+               msgCalcMissingArgMoveDist       : '%s : %s : Missing argument - MoveByThisDistance',\r
+               msgCalcMissingArgMoveBear       : '%s : %s : Missing argument - MoveByThisBearing',\r
+               msgCalcWrongTypeMoveDist        : '%s : %s : TypeMismatch - MoveByThisDistance',\r
+               msgCalcWrongTypeMoveBear        : '%s : %s : TypeMismatch - MoveByThisBearing',\r
+               msgCancelBadArg                         : '%s : %s : BadArgument – cancel type',\r
+               msgCancelMissingType            : '%s : %s : Missing cancel type',\r
+               msgCancelWrongType                      : '%s : %s : Wrong cancel type' ,\r
+               msgNone                                         : ''    \r
+       };\r
+               \r
+\r
+}) ()\r
+\r