HTML and CSS Reference
In-Depth Information
if (geo) {
geo.getGeopositionAsync().then(function (position) {
WinJS.xhr({
url: "http://nominatim.openstreetmap.org"
+ "/reverse?format = json&lat="
+ position.coordinate.latitude
+ "&lon=" + position.coordinate.longitude
}).then(function (data) {
var dataObject = JSON.parse(data.response);
if (dataObject.address.road) {
var date = new Date();
var time = date.getHours() + ":" + date.getMinutes()
+ ":" + date.getSeconds();
document.getElementById("geo").innerText =
dataObject.address.road + " (" + time + ")";
}
});
});
}
complete();
});
currentPromise.then(function () {
if (tracking) {
setTimeout(trackLocation, 5000);
}
});
}
WinJS.Namespace.define("Location", {
startTracking: function () {
tracking = true;
trackLocation();
},
stopTracking: function () {
tracking = false;
return currentPromise;
}
});
})();
Using Location Tracking
The Windows 8 geolocation service is available through the Windows.Devices.Geolocation.
Geolocator object. You can subscribe to receive events when the location information changes,
but I want to demonstrate a repeating background task, so I have used the getGeopositio-
nAsync method, which produces a snapshot of the current location. This is an asynchronous
operation, and so the getGeopositionAsync method returns a Promise object that completes
when the location information is available.
Search WWH ::




Custom Search