serviceproviders/jsapi/platformservices/src/geolocation.js
changeset 38 02682e02e51f
child 50 5dae2c62e9b6
equal deleted inserted replaced
37:5d0ec8b709be 38:02682e02e51f
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Defination of class CCalendarInterface
       
    15 *
       
    16 */
       
    17 
       
    18 var _infinity = 1.7976931348623157E+10308;
       
    19 /*function PositionError()
       
    20 {
       
    21 	this.UNKNOWN_ERROR = 0;
       
    22 	this.PERMISSION_DENIED = 1;
       
    23 	this.POSITION_UNAVAILABLE = 2;
       
    24 	this.TIMEOUT = 3;
       
    25 	this.code ;
       
    26 	this.message ;
       
    27 }
       
    28 function Coordinates()
       
    29 {
       
    30 	this.latitude = null;
       
    31 	this.longitude = null;
       
    32 	this.altitude = null;
       
    33 	this.accuracy = null;
       
    34 	this.altitudeAccuracy = null;
       
    35 	this.heading = null;
       
    36 	this.speed = null;
       
    37 }
       
    38 function Position()
       
    39 {
       
    40 	this.coords = null;
       
    41 	this.timestamp = null;
       
    42 }
       
    43 function PositionOptions()
       
    44 {
       
    45 	this.enableHighAccuracy = null;
       
    46 	this.timeout = null;
       
    47 	this.maximumAge = null;
       
    48 }*/
       
    49 
       
    50 function TransIdCbMap()
       
    51 {
       
    52 	this.TransactionID = null;
       
    53 	this.success_callback = null;
       
    54 	this.error_callback = null;
       
    55 }
       
    56 
       
    57 function __device_geolocation_descriptor(provider)
       
    58 {
       
    59 	this.interfaceName = provider.interfaceName;
       
    60 	this.version = provider.version;
       
    61 }
       
    62 
       
    63 function __device_geolocation_getCurrentPosition(success_cb,fail_cb,posOptions)
       
    64 {
       
    65   
       
    66 	return this.provider.getLocation(success_cb,fail_cb,posOptions);
       
    67 }
       
    68 
       
    69 
       
    70 function __device_geolocation_watchPosition(success_cb,fail_cb,posOpts)
       
    71 {
       
    72 	return this.provider.traceLocation(success_cb,fail_cb,posOpts);
       
    73 }
       
    74 
       
    75 function __device_geolocation_clearWatch(watchId)
       
    76 {
       
    77 	this.provider.clearTrace(watchId);
       
    78 }
       
    79 
       
    80 // Private location prototype: called from service factory
       
    81 function __device_geolocation(provider)
       
    82 {
       
    83 	//Private properties
       
    84 	this.provider = provider;
       
    85 	//Read-only properties
       
    86 	this.interfaceName = provider.descriptor.interfaceName;
       
    87 	this.version = provider.descriptor.version;
       
    88 	//one shot retrival of the current position of the device
       
    89 	this.getCurrentPosition = __device_geolocation_getCurrentPosition;
       
    90 	
       
    91 	//Register to get contineous update of device location change
       
    92 	this.watchPosition = __device_geolocation_watchPosition;
       
    93 	
       
    94 	//Clear previously invoke watchPosition Request
       
    95 	this.clearWatch = __device_geolocation_clearWatch;
       
    96 }
       
    97 
       
    98 // geolocation service interface
       
    99 
       
   100 // Namepace: com.nokia.device.service
       
   101 
       
   102 var __device_geolocation_service_entry = {"name": null, 
       
   103 					     "version": null,
       
   104 					     "proto": __device_geolocation,
       
   105 					     "descriptor": __device_geolocation_descriptor,
       
   106 					     "providers": [{"descriptor": __sp_location_descriptor, "instance": __sp_location_instance}]
       
   107 					    };
       
   108 
       
   109 
       
   110 
       
   111 
       
   112 
       
   113 
       
   114 /*
       
   115 Copyright � 2009 Nokia. All rights reserved.
       
   116 Code licensed under the BSD License:
       
   117 Software License Agreement (BSD License) Copyright � 2009 Nokia.
       
   118 All rights reserved.
       
   119 Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
       
   120 
       
   121 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
       
   122 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
       
   123 Neither the name of Nokia Corporation. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Nokia Corporation. 
       
   124 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
   125 
       
   126 version: 1.0
       
   127 */
       
   128 
       
   129 
       
   130 // S60 sp-based location provider
       
   131  function Location_PositionError()
       
   132 	{
       
   133 		this.UNKNOWN_ERROR = 0;
       
   134 		this.PERMISSION_DENIED = 1;
       
   135 		this.POSITION_UNAVAILABLE = 2;
       
   136 		this.TIMEOUT = 3;
       
   137 		this.code ;
       
   138 		this.message ;
       
   139 	}
       
   140 	function Location_Coordinates()
       
   141 	{
       
   142 		this.latitude = null;
       
   143 		this.longitude = null;
       
   144 		this.altitude = null;
       
   145 		this.accuracy = null;
       
   146 		this.altitudeAccuracy = null;
       
   147 		this.heading = null;
       
   148 		this.speed = null;
       
   149 	}
       
   150 	function Location_Position()
       
   151 	{
       
   152 		this.coords = null;
       
   153 		this.timestamp = null;
       
   154 	}
       
   155 	function Location_PositionOptions()
       
   156 	{
       
   157 		this.enableHighAccuracy ;
       
   158 		this.timeout;
       
   159 		this.maximumAge;
       
   160 	}
       
   161 
       
   162 
       
   163 
       
   164 
       
   165 
       
   166 var __sp_location_trace_transactionId = -1;
       
   167 
       
   168 function __sp_location_handle_error(errorCallback,errorCode,errorMessage)
       
   169 	{ 
       
   170 		if( (errorCallback != undefined) && (typeof errorCallback == 'function') && (errorCallback != null) )
       
   171 		{
       
   172 			//create a new position error object
       
   173 			var posError = new Location_PositionError(); 
       
   174 			if( (-21) == errorCode )
       
   175 			{
       
   176 				posError.code = posError.PERMISSION_DENIED;
       
   177 				posError.message = "permission denied";
       
   178 				
       
   179 			}
       
   180 			else if( (-33) == errorCode )
       
   181 			{
       
   182 	
       
   183 				posError.code = posError.TIMEOUT;
       
   184 				posError.message = "request timed out";
       
   185 	
       
   186 				
       
   187 			}
       
   188 			else 
       
   189 			{
       
   190 				posError.code = posError.UNKNOWN_ERROR;
       
   191 				posError.message = "UnKnown Error";
       
   192 				
       
   193 			}
       
   194 			
       
   195 			//Invoke user supplied error callback
       
   196 			errorCallback( posError );
       
   197 			
       
   198 		} else {
       
   199 			var posError = new Location_PositionError();
       
   200 			posError.code = posError.UNKNOWN_ERROR;
       
   201 			posError.message = "UnKnown Error";
       
   202 			throw posError;
       
   203 		}
       
   204 		
       
   205 		
       
   206 		
       
   207 	}
       
   208 
       
   209 function __sp_location_descriptor()
       
   210 {
       
   211 	//Read-only properties
       
   212 	this.interfaceName = "geolocation";
       
   213   if(window.__Service_Interface_Ver)
       
   214 	this.version =__Service_Interface_Ver;
       
   215   else
       
   216 	this.version =1.0;
       
   217 	//Class-static properties 
       
   218 }
       
   219 
       
   220 
       
   221 var obj;
       
   222 
       
   223 function __sp_getLocation_cb(arg1, arg2, arg3)
       
   224 	{ 
       
   225 	var CbObj;
       
   226     
       
   227     
       
   228     CbObj = glob_obj.getFromArray(arg1);
       
   229     
       
   230     
       
   231     
       
   232     if (CbObj) {
       
   233         success_cb1 = CbObj.success_cb;
       
   234         error_cb = CbObj.error_cb;
       
   235     }
       
   236     
       
   237     else {
       
   238         alert("Geolocation: __sp_getLocation_cb: Callback not found ");
       
   239 		return;
       
   240     }
       
   241     
       
   242 	
       
   243 		if( arg3.ErrorCode )
       
   244 		{
       
   245 			//process error condition
       
   246 				////alert("arg3.ErrorCode");
       
   247 				__sp_location_handle_error(error_cb,arg3.ErrorCode,arg3.ErrorMessage);
       
   248 				return;			
       
   249 		}
       
   250 		//there is no error so invoke consumer supplied success callback
       
   251 		else
       
   252 		{    
       
   253 			 var _pos_coord = new Location_Coordinates();
       
   254 			_pos_coord.longitude = (arg3.ReturnValue.Longitude == undefined)?null:arg3.ReturnValue.Longitude;
       
   255 			_pos_coord.latitude = (arg3.ReturnValue.Latitude == undefined)?null:arg3.ReturnValue.Latitude;
       
   256 			_pos_coord.altitude = (arg3.ReturnValue.Altitude == undefined)?null:arg3.ReturnValue.Altitude;
       
   257 			_pos_coord.accuracy = (arg3.ReturnValue.HorizontalAccuracy == undefined)?null:arg3.ReturnValue.HorizontalAccuracy;			
       
   258 			_pos_coord.altitudeAccuracy = (arg3.ReturnValue.VerticalAccuracy == undefined)?null:arg3.ReturnValue.VerticalAccuracy;
       
   259 			_pos_coord.heading = (arg3.ReturnValue.Heading == undefined)?null:arg3.ReturnValue.Heading;
       
   260 			_pos_coord.speed = (arg3.ReturnValue.HorizontalSpeed == undefined)?null:arg3.ReturnValue.HorizontalSpeed;
       
   261 			
       
   262 			//Position Object
       
   263 			var _pos_data = new Location_Position();
       
   264 
       
   265 			_pos_data.coords = {};
       
   266 			modifyObjectBaseProp(_pos_data.coords);
       
   267 			_pos_data.coords =_pos_coord;
       
   268 			_pos_data.timestamp = new Date();
       
   269 			
       
   270 			//Invoke consumer callback			
       
   271 			success_cb1( _pos_data );			
       
   272 			delete _pos_data.timestamp;
       
   273 			delete _pos_data;
       
   274 			delete _pos_coord;	
       
   275 		}
       
   276 		 glob_obj.removeFromArray(arg1);	
       
   277 	}
       
   278 	
       
   279 //Gets the current location 
       
   280 function __sp_getLocation(success_cb,fail_cb,posOptions)
       
   281 {    
       
   282      
       
   283 	
       
   284 		
       
   285 	 if((success_cb == undefined) || (success_cb == null) || (typeof(success_cb) != "function"))
       
   286 			{
       
   287 				var errorFormat = "Wrong callback type";
       
   288 		       __sp_location_handle_error(fail_cb,0,errorFormat);
       
   289 				
       
   290 			}	
       
   291 	
       
   292 	
       
   293 	if ((fail_cb != undefined)) {
       
   294 				if ((fail_cb != null)
       
   295 				    &&(fail_cb != "")
       
   296 					&& (typeof(fail_cb) != "function")) {						
       
   297 						var errorObject = new Location_PositionError();
       
   298 						errorObject.code = -1;
       
   299 						throw errorObject;	
       
   300 				}
       
   301 			}
       
   302 
       
   303 
       
   304 	var returnValue;
       
   305 	//Input object to be passed to Location provider
       
   306 	var criteria = {};
       
   307 	modifyObjectBaseProp(criteria);
       
   308 	criteria.LocationInformationClass = "GenericLocationInfo";
       
   309 	
       
   310 	var updateoptions = {};
       
   311 	modifyObjectBaseProp(updateoptions);
       
   312 	updateoptions.UpdateInterval = 0;
       
   313 	
       
   314 	if (posOptions != undefined && posOptions != null) {
       
   315 		if ((typeof(posOptions) != "object")) {
       
   316 			////alert("!= object");
       
   317 			var errorMessage = "Wrong posOptions type";
       
   318 			__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   319 			return;
       
   320 		}
       
   321 	}		
       
   322 			
       
   323 	if( posOptions != undefined )
       
   324 	{
       
   325 	
       
   326 		if (posOptions.maximumAge != undefined ) {
       
   327 		
       
   328 			if (posOptions.maximumAge) {
       
   329 				//If the param is specified and it is a number
       
   330 				if ((posOptions.maximumAge == Infinity)) {////alert("infinty");
       
   331 					if ((posOptions.enableHighAccuracy == undefined) ||
       
   332 					(typeof(posOptions.enableHighAccuracy) == "boolean")) {															
       
   333 						var arg3 = this.so.ILocation.GetLastPosition();
       
   334 						if (arg3.ErrorCode < 0) { 						
       
   335 							var errorMessage = "Invalid input type";
       
   336 							__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   337 							return;
       
   338 							
       
   339 						}
       
   340 						
       
   341 						var _pos_coord = new Location_Coordinates();
       
   342 						_pos_coord.longitude = (arg3.ReturnValue.Longitude == undefined) ? null : arg3.ReturnValue.Longitude;
       
   343 						_pos_coord.latitude = (arg3.ReturnValue.Latitude == undefined) ? null : arg3.ReturnValue.Latitude;
       
   344 						_pos_coord.altitude = (arg3.ReturnValue.Altitude == undefined) ? null : arg3.ReturnValue.Altitude;
       
   345 						_pos_coord.accuracy = (arg3.ReturnValue.HorizontalAccuracy == undefined) ? null : arg3.ReturnValue.HorizontalAccuracy;
       
   346 						_pos_coord.altitudeAccuracy = (arg3.ReturnValue.VerticalAccuracy == undefined) ? null : arg3.ReturnValue.VerticalAccuracy;
       
   347 						_pos_coord.heading = (arg3.ReturnValue.Heading == undefined) ? null : arg3.ReturnValue.Heading;
       
   348 						_pos_coord.speed = (arg3.ReturnValue.HorizontalSpeed == undefined) ? null : arg3.ReturnValue.HorizontalSpeed;
       
   349 						
       
   350 						//Position Object
       
   351 						var _pos_data = new Location_Position();
       
   352 						_pos_data.coords = {};
       
   353 						modifyObjectBaseProp(_pos_data.coords);
       
   354 						_pos_data.coords = _pos_coord;
       
   355 						_pos_data.timestamp = new Date();
       
   356 						
       
   357 						//Invoke consumer callback
       
   358 						
       
   359 						success_cb(_pos_data);
       
   360 						delete _pos_data.timestamp;
       
   361 						delete _pos_data;
       
   362 						delete _pos_coord;
       
   363 						return;
       
   364 						
       
   365 					}
       
   366 					
       
   367 				
       
   368 				}
       
   369 			
       
   370 			if (!(isNaN(parseInt(posOptions.maximumAge)))) {
       
   371 					
       
   372 					if ((posOptions.maximumAge == 0)) {
       
   373 						
       
   374 						var errorMessage = "Invalid input type";
       
   375 						__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   376 						return;
       
   377 					}
       
   378 					
       
   379 					    //alert("number");
       
   380 						updateoptions.UpdateMaxAge = posOptions.maximumAge ;
       
   381 						//alert("updateoptions.UpdateMaxAget"+ updateoptions.UpdateMaxAge);
       
   382 					
       
   383 				}
       
   384 				else {
       
   385 					//alert("!number");
       
   386 					var errorMessage = "Invalid input type";
       
   387 					__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   388 					return;
       
   389 				}
       
   390 				
       
   391 			}
       
   392 			
       
   393 			else if ((posOptions.maximumAge == null) || (posOptions.maximumAge == "")) { ////alert("null");
       
   394 					}
       
   395 			
       
   396 		}
       
   397 		
       
   398 		//check if timeout is supplied.
       
   399 		if((posOptions.enableHighAccuracy !== undefined ))
       
   400 		{  
       
   401 			
       
   402 			if(posOptions.enableHighAccuracy == true) {////alert("1");
       
   403 					criteria.EnableHighAccuracy = posOptions.enableHighAccuracy;
       
   404 				}				
       
   405 			else if(posOptions.enableHighAccuracy == false) {	////alert("2e");					
       
   406 						criteria.EnableHighAccuracy = posOptions.enableHighAccuracy;
       
   407 					}				
       
   408 			else if ((posOptions.enableHighAccuracy == null) || (posOptions.enableHighAccuracy == "")) {
       
   409 							}
       
   410 			else{ ////alert("acc = else");
       
   411 				if ((typeof(posOptions.enableHighAccuracy) != "boolean")) {
       
   412 					var errorFormat1 = "Wrong value for enableHighAccuracy param";
       
   413 					__sp_location_handle_error(fail_cb, 0, errorFormat1);
       
   414 				
       
   415 					return;
       
   416 				}
       
   417 				
       
   418 			}
       
   419 			
       
   420 		}
       
   421 		
       
   422 			
       
   423 		if (posOptions.timeout !== undefined) {
       
   424 			if ((posOptions.timeout !== null) || ((posOptions.timeout !== ""))) {
       
   425 				//alert("12");
       
   426 				if ((posOptions.timeout == Infinity)) {
       
   427 					//alert("12345");
       
   428 					//alert("infinty condition");
       
   429 					var errorMessage = "Invalid input type";
       
   430 					__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   431 					return;
       
   432 				}
       
   433 				
       
   434 				else 
       
   435 					if (!(isNaN(parseInt(posOptions.timeout)))) {
       
   436 						//alert("timeout = 0")
       
   437 						if ((posOptions.timeout <= 2147483647)) {
       
   438 						
       
   439 						if ((posOptions.timeout == 0)) {
       
   440 							//alert("inside if int");
       
   441 							var errorMessage = "Invalid input type";
       
   442 							__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   443 							return;
       
   444 						}
       
   445 						//alert("true condition");
       
   446 						updateoptions.UpdateTimeOut = posOptions.timeout;
       
   447 						
       
   448 					}
       
   449 					else{
       
   450 						var errorMessage = "Invalid input type";
       
   451 				       __sp_location_handle_error(fail_cb, 0, errorMessage);
       
   452 				       return;
       
   453 					}
       
   454 			}
       
   455 		}
       
   456 		else if ((posOptions.timeout === null) || ((posOptions.timeout === ""))) {
       
   457 				//alert("true condition");
       
   458 			
       
   459 			}
       
   460 			else {
       
   461 				//alert("!number");
       
   462 				var errorMessage = "Invalid input type";
       
   463 				__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   464 				return;
       
   465 			}		
       
   466 		}   
       
   467 		     
       
   468 	}
       
   469 
       
   470 	// Setting PartialUpdates to false ensures that user gets at least 
       
   471 	// BasicLocationInformation (Longitude, Latitude, and Altitude.)
       
   472 	updateoptions.PartialUpdates = false;
       
   473 		
       
   474 	criteria.Updateoptions = updateoptions;
       
   475 	
       
   476 	try 
       
   477 	{     
       
   478 		temp_scb = success_cb;
       
   479 		temp_ecb = fail_cb;
       
   480 		var rval = this.so.ILocation.GetLocation(criteria, this.getLocationCb);   
       
   481 		if (rval.TransactionID) {
       
   482             glob_obj.addToGlobalArray(rval.TransactionID, success_cb, fail_cb);
       
   483         }
       
   484 		
       
   485 		delete updateoptions;
       
   486 		delete criteria; 
       
   487 		
       
   488 		if(rval.ErrorCode != 0)
       
   489 			{   		
       
   490 			//process error condition
       
   491 	
       
   492 			__sp_location_handle_error(fail_cb,rval.ErrorCode,rval.ErrorMessage);
       
   493 			
       
   494 			//__sp_location_handle_error(__fail_cb,-1);
       
   495 			return;
       
   496 			}
       
   497 
       
   498 	}
       
   499 	
       
   500 	catch (e) 
       
   501 	{
       
   502 		__device_handle_exception (e, "__sp_getLocation: " + e);
       
   503 	}
       
   504 }
       
   505 
       
   506 
       
   507 
       
   508 var __sp_location_trace_ucb = null;
       
   509 var __sp_location_fail_cb  = null;
       
   510 
       
   511 function __sp_traceLocation_cb(arg1, arg2, arg3){
       
   512 	
       
   513 		 var CbObj;
       
   514     
       
   515     
       
   516 	    CbObj = glob_obj.getFromArray(arg1);
       
   517 	    
       
   518 	    
       
   519 	    
       
   520 	    if (CbObj) {
       
   521 	        success_cb = CbObj.success_cb;
       
   522 	        error_cb = CbObj.error_cb;
       
   523 	    }
       
   524 	    
       
   525 	    else {
       
   526 	        alert("Geolocation: __sp_traceLocation_cb: Callback not found ");
       
   527 			return;
       
   528 	    }
       
   529     
       
   530 		
       
   531 			
       
   532 		if( arg3.ErrorCode )
       
   533 		{	
       
   534 			//process error condition			
       
   535 			__sp_location_handle_error(error_cb,
       
   536 									   arg3.ErrorCode,
       
   537 									   arg3.ErrorMessage);
       
   538 				
       
   539 		}
       
   540 		
       
   541 		else//there is no error so invoke consumer supplied success callback
       
   542 		{   
       
   543 			
       
   544 			 var _pos_coord = new Location_Coordinates();
       
   545 			_pos_coord.longitude = (arg3.ReturnValue.Longitude == undefined)?null:arg3.ReturnValue.Longitude;
       
   546 			_pos_coord.latitude = (arg3.ReturnValue.Latitude == undefined)?null:arg3.ReturnValue.Latitude;
       
   547 			_pos_coord.altitude = (arg3.ReturnValue.Altitude == undefined)?null:arg3.ReturnValue.Altitude;
       
   548 			_pos_coord.accuracy = (arg3.ReturnValue.HorizontalAccuracy == undefined)?null:arg3.ReturnValue.HorizontalAccuracy;		
       
   549 			_pos_coord.altitudeAccuracy = (arg3.ReturnValue.VerticalAccuracy == undefined)?null:arg3.ReturnValue.VerticalAccuracy;
       
   550 			_pos_coord.heading = (arg3.ReturnValue.Heading == undefined)?null:arg3.ReturnValue.Heading;
       
   551 			_pos_coord.speed = (arg3.ReturnValue.HorizontalSpeed == undefined)?null:arg3.ReturnValue.HorizontalSpeed;
       
   552 			
       
   553 			//Position Object
       
   554 			var _pos_data = new Location_Position();
       
   555 			_pos_data.coords = {};
       
   556 			modifyObjectBaseProp(_pos_data.coords);
       
   557 			_pos_data.coords =_pos_coord;
       
   558 			_pos_data.timestamp = new Date();
       
   559 			
       
   560 			
       
   561 			//Invoke consumer callback
       
   562 			
       
   563 			success_cb( _pos_data );
       
   564 			delete _pos_data.timestamp;
       
   565 			delete _pos_data;
       
   566 			delete _pos_coord;
       
   567 			return;
       
   568 		}
       
   569 	 glob_obj.removeFromArray(arg1);	
       
   570 	}
       
   571 
       
   572 //Funtion to obtain periodic updates
       
   573 function __sp_traceLocation(trace_cb, fail_cb,posOptions)
       
   574 {
       
   575 
       
   576 	
       
   577 	if((trace_cb == undefined) || (trace_cb == null) || (typeof(trace_cb) != "function"))
       
   578 			{
       
   579 				var errorMessage = "Wrong callback type";
       
   580 				__sp_location_handle_error(fail_cb,0,errorMessage);
       
   581 				return;				
       
   582 			}
       
   583 	
       
   584 	
       
   585 	if((typeof trace_cb != 'function' ))
       
   586 	{////alert("not fun");
       
   587 		var errorMessage = "Wrong callback type";
       
   588 		__sp_location_handle_error(fail_cb,0,errorMessage);
       
   589 		return;
       
   590 	}
       
   591 	
       
   592 	if ((fail_cb != undefined)) {////alert("!= fail_cb");
       
   593 				if ((fail_cb != null)
       
   594 				    &&(fail_cb != "")
       
   595 					&& (typeof(fail_cb) != "function")) {
       
   596 						//////alert("fail_cb fail");
       
   597 					var errorObject = new Location_PositionError();
       
   598 					errorObject.code = -1;
       
   599 					throw errorObject;	
       
   600 				}
       
   601 			}
       
   602    
       
   603    
       
   604 	   
       
   605 	var thisobj = this;
       
   606 	
       
   607 	
       
   608 	
       
   609 	var updateoptions = {};
       
   610 	modifyObjectBaseProp(updateoptions);
       
   611 	updateoptions.UpdateInterval = 0;
       
   612 	var criteria = {};
       
   613 	modifyObjectBaseProp(criteria);
       
   614 	criteria.LocationInformationClass = "GenericLocationInfo";	
       
   615 	
       
   616 	if (posOptions != undefined && posOptions != null) {
       
   617 		if ((typeof(posOptions) != "object")) {
       
   618 			////alert("!= object");
       
   619 			var errorMessage = "Wrong posOptions type";
       
   620 			__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   621 			return;
       
   622 		}
       
   623 	}		
       
   624 
       
   625 	if (posOptions != undefined) {
       
   626 	
       
   627 	
       
   628 		if ((posOptions.enableHighAccuracy !== undefined)) {
       
   629 		
       
   630 			if (posOptions.enableHighAccuracy == true) {////alert("1");
       
   631 				criteria.EnableHighAccuracy = posOptions.enableHighAccuracy;
       
   632 			}
       
   633 			else 
       
   634 				if (posOptions.enableHighAccuracy == false) { ////alert("2e");					
       
   635 					criteria.EnableHighAccuracy = posOptions.enableHighAccuracy;
       
   636 				}
       
   637 				else 
       
   638 					if ((posOptions.enableHighAccuracy == null) || (posOptions.enableHighAccuracy == "")) {
       
   639 					}
       
   640 					
       
   641 					else { 
       
   642 						if ((typeof(posOptions.enableHighAccuracy) != "boolean")) {
       
   643 							var errorFormat = "Wrong value for enableHighAccuracy param";
       
   644 							__sp_location_handle_error(fail_cb, 0, errorFormat);
       
   645 							return;
       
   646 						}
       
   647 						
       
   648 					}
       
   649 			
       
   650 		}	
       
   651 
       
   652 	
       
   653 	if (posOptions.timeout !== undefined) {
       
   654 			if ((posOptions.timeout !== null)  || ((posOptions.timeout !== ""))) {
       
   655 					//alert("12");
       
   656 				if ((posOptions.timeout == Infinity)) {
       
   657 					//alert("12345");
       
   658 					//alert("infinty condition");
       
   659 					var errorMessage = "Invalid input type";
       
   660 					__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   661 					return;
       
   662 				}
       
   663 				
       
   664 				else if (!(isNaN(parseInt(posOptions.timeout)))) {//alert("timeout = 0")
       
   665 					
       
   666 					if ((posOptions.timeout == 0) ) {
       
   667 						//alert("inside if int");
       
   668 						var errorMessage = "Invalid input type";
       
   669 						__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   670 						return;
       
   671 					}
       
   672 						//alert("true condition");
       
   673 						updateoptions.UpdateTimeOut = posOptions.timeout ;
       
   674 					
       
   675 				}	
       
   676 			}	
       
   677 				
       
   678 		else if ((posOptions.timeout === null) ||((posOptions.timeout === ""))) {
       
   679 					//alert("true condition");
       
   680 					//	updateoptions.UpdateTimeOut = posOptions.timeout * 1000;
       
   681 				}
       
   682 				else {
       
   683 					//alert("!number");
       
   684 					var errorMessage = "Invalid input type";
       
   685 					__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   686 					return;
       
   687 				}	
       
   688 				
       
   689 					
       
   690 		}
       
   691 		//check that update interval if specified is an integer.
       
   692 	 
       
   693 		if( typeof posOptions.maximumAge != 'undefined')
       
   694 		{
       
   695 			
       
   696 						
       
   697 			if(posOptions.maximumAge == _infinity)
       
   698 				{
       
   699 					updateoptions.UpdateTimeOut = 0;
       
   700 					updateoptions.UpdateMaxAge = 2147483647; //2^31 - 1
       
   701 
       
   702 				}
       
   703 			
       
   704 			//If the param is specified and it is a number 
       
   705 			else if(!(isNaN(parseInt(posOptions.maximumAge))))
       
   706 			{
       
   707 		  		updateoptions.UpdateMaxAge = posOptions.maximumAge ;
       
   708 			}
       
   709 				
       
   710 			else if ((posOptions.maximumAge === null) || ((posOptions.maximumAge === ""))) {
       
   711 				//alert("true condition");
       
   712 			//	updateoptions.UpdateTimeOut = posOptions.timeout * 1000;
       
   713 				}
       
   714 			else {
       
   715 				//alert("!number");
       
   716 				var errorMessage = "Invalid input type";
       
   717 				__sp_location_handle_error(fail_cb, 0, errorMessage);
       
   718 				return;
       
   719 			}		
       
   720 				
       
   721 		}
       
   722 		
       
   723 	}
       
   724 
       
   725 	// Setting PartialUpdates to false ensures that user gets at least 
       
   726 	// BasicLocationInformation (Longitude, Latitude, and Altitude.)	
       
   727 	updateoptions.PartialUpdates = false;
       
   728 	
       
   729 	criteria.Updateoptions = updateoptions;
       
   730 	
       
   731 	try 
       
   732 	{
       
   733 		temp_scb = trace_cb;
       
   734 		temp_ecb = fail_cb;
       
   735 		var rval = this.so.ILocation.Trace(criteria,this.traceCb);
       
   736 		if (rval.TransactionID) {
       
   737             glob_obj.addToGlobalArray(rval.TransactionID, trace_cb, fail_cb);
       
   738         }
       
   739 		delete updateoptions;
       
   740 		delete criteria;
       
   741 		if(rval.ErrorCode != 0)
       
   742 			{
       
   743 				//process error condition
       
   744 				__sp_location_handle_error(fail_cb,rval.ErrorCode,rval.ErrorMessage);				
       
   745 				return;
       
   746 			}
       
   747 		
       
   748 		return rval.TransactionID;
       
   749 	}
       
   750 
       
   751 	catch (e) 
       
   752 	{
       
   753 		__device_handle_exception (e, "__sp_traceLocation: " + e);  
       
   754 	}
       
   755 }
       
   756 
       
   757 //clears any outstanding Trace requests
       
   758 function __sp_clearTrace(watchId)
       
   759 { 
       
   760 
       
   761 		if(typeof watchId != 'number')	
       
   762 		{
       
   763 			        var errorMessage = "Invalid input type";
       
   764 				   __sp_location_handle_error(fail_cb,0,errorMessage);		
       
   765 		}
       
   766 		 
       
   767 		var locationParams = {            
       
   768             TransactionID : watchId
       
   769         };
       
   770 		
       
   771 		try 
       
   772 		{
       
   773 			
       
   774 			var result = this.so.ILocation.Cancel(locationParams);
       
   775 			
       
   776 		//Just ignore the error
       
   777 			
       
   778 		}
       
   779 		catch (e) 
       
   780 		{
       
   781 			__device_handle_exception (e, "__sp_clearTrace: " + e );
       
   782 		
       
   783 		}
       
   784 		 
       
   785 
       
   786 }
       
   787 
       
   788 
       
   789 function __sp_location_instance()
       
   790 {
       
   791 	
       
   792 	//Descriptor
       
   793 	this.descriptor = new __sp_location_descriptor();
       
   794 	//Core methods
       
   795 	this.getLocation = __sp_getLocation;
       
   796 	this.getLocationCb = __sp_getLocation_cb;
       
   797 	//Extended methods
       
   798 	this.traceLocation = __sp_traceLocation;
       
   799 	this.traceCb = __sp_traceLocation_cb;
       
   800 	this.clearTrace = __sp_clearTrace;
       
   801 	
       
   802 	//Private data
       
   803 
       
   804 	try
       
   805 	{
       
   806 	
       
   807 		this.so = device.getServiceObject("Service.Location", "ILocation");
       
   808 	
       
   809 	}
       
   810 	catch (e)
       
   811 	{
       
   812 		this.so = null;
       
   813 		__device_handle_exception (e, "Location service not available");
       
   814 	}
       
   815 }