언어 설정

Menu
Sites
Language

Get watch current location in web application

To watch your current location you can use watchPosition() method from Geolocation API (and method clearWatch() to stop watching). Also don't forget to add "location" privilage and "location.gps" feature to config.xml.

Responses

1 댓글
James Bond

So my code (app.js) is like this:
 
( function() {
        /**
         * Back key event handler
         */
 var options = {enableHighAccuracy: true, maximumAge: 600000, timeout: 0};
 var watchID;
 function successCallback(position)
 {
     var page = document.getElementsByClassName('ui-title')[0];
     page.innerHTML = position;
    console.log(position);
 }
 function errorCallback(error)
 {
  console.log(error);
     
 }
        var watchID = navigator.geolocation.watchPosition(successCallback, errorCallback, options);
        window.addEventListener('tizenhwkey', function(ev) {
            if (ev.keyName === "back") {
                var page = document.getElementsByClassName('ui-page-active')[0],
                    pageid = page ? page.id : "";
                if (pageid === "main") {
                    try {
                        tizen.application.getCurrentApplication().exit();
                    } catch (ignore) {}
                } else {
                    window.history.back();
                }
            }
        });
    }());
 
Should work no? Still on Emulator it breaks at console.log(error) (i've set the location and gps in config.xml)