/* * operaGeolocationWrapper.js * --------------------------------- * Wrapper for Opera Geolocation functionality using Nokia WRT location service object * * Currently, only the 'one shot' location functionality is available. * * Licensed under the BSD License. * Originally developed by Metropolia Media Works / Andrew Wharton * Supported by Forum Nokia * version: 1.0 * -------------- */ /* * Global variables */ //used to store the name of the callback function so it is globally accessible var _callbackName; navigator.geolocation = new Object(); navigator.geolocation.getCurrentPosition = getCurrentPosition; /* * getCurrentPosition * ------------------ * Calls the WRT GetLocation asynchronous function and returns immediately */ function getCurrentPosition(callback) { // save the callback to a global variable for later use _callbackName = callback; // get a service object var so = device.getServiceObject("Service.Location", "ILocation"); // create a criteria object var criteria = new Object(); criteria.LocationInformationClass = "GenericLocationInfo"; // call the GetLocation method // passes criteria object and callback method as arguments result = so.ILocation.GetLocation(criteria, _callback); // return result so that code can continue return result; } /* * _callback * --------- * Intermediate callback funtion to modify the position object before passing it to the real callback function * -takes the Nokia ReturnValue object, extracts the required information * -creates a new position object in the W3C form * -invokes the user defined callback using the modified object as argument */ var _callback = function(transId, eventCode, result) { // store the nokia position object info into a temporary location var latitude = result.ReturnValue.Latitude; var longitude = result.ReturnValue.Longitude; var altitude = result.ReturnValue.Altitude; var altitudeAccuracy = null; // unable to obtain, therefore must be null as per W3C geolocation spec var heading = result.ReturnValue.TrueCourse; var speed = result.ReturnValue.HorizontalSpeed; // Create the new position object var Position = new Object(); Position.coords = new Object(); // add attributes to new position object Position.coords.latitude = latitude; Position.coords.longitude = longitude; Position.coords.altitude = altitude; Position.coords.altitudeAccuracy = altitudeAccuracy; Position.coords.heading = heading; Position.coords.speed = speed; // invoke the user defined callback function with the Position object as argument _callbackName(Position); }