platformservices_20_specific.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //W3C GeoLocation service object based on com.nokia.device.geolocation Interface
  2. var serviceObj = null;
  3. // Variable for watch id. it is used for removing watch.
  4. var watchId = null;
  5. /*
  6. * Options for retrieving position info
  7. * PositionOptions schema
  8. * {
  9. * "enableHighAccuracy": boolean, //currently Not Supported
  10. * "timeout": number,
  11. * "maximumAge": number
  12. * }
  13. */
  14. var positionOpts = null;
  15. function initSystemServices(){
  16. positionOpts = {
  17. timeout: 30000,
  18. maximumAge: 1000
  19. };
  20. try {
  21. serviceObj = nokia.device.load("geolocation");
  22. GetLocationOneShot();
  23. }
  24. catch (e) {
  25. var error = e.toString();
  26. alert(error);
  27. }
  28. }
  29. /*
  30. * Gets one-time data for hosting device position.
  31. */
  32. function GetLocationOneShot(){
  33. try {
  34. serviceObj.getCurrentPosition(success_callback, error_callback, positionOpts);
  35. }
  36. catch (e) {
  37. var error = e.toString();
  38. alert(error);
  39. }
  40. }
  41. /*
  42. * Starts permanent monitoring of position and gets notification whenever hosting device position changes
  43. */
  44. function startMonitoring(){
  45. try {
  46. watchId = serviceObj.watchPosition(success_callback, error_callback, positionOpts);
  47. }
  48. catch (e) {
  49. alert(e.toString());
  50. }
  51. }
  52. /*
  53. * Stops position monitoring
  54. */
  55. function stopMonitoring(){
  56. try {
  57. if (watchId != null)
  58. serviceObj.clearWatch(watchId);
  59. watchId = null;
  60. }
  61. catch (e) {
  62. alert(e.toString());
  63. }
  64. }
  65. /*
  66. * Callback function that is called asynchronously with positionInformation.
  67. * result - positionInformation
  68. */
  69. function success_callback(result){
  70. displayPositionData(result);
  71. }
  72. /*
  73. * Gets called in case of an error
  74. */
  75. function error_callback(result){
  76. alert('Error retrieving position\ncode :' + result.code + '\nmessage: ' + result.message);
  77. channelmonitoractive = true;
  78. MonitorToggle_onclick(document.getElementById("MonitorToggle"));
  79. }