HTML and CSS Reference
In-Depth Information
FIGURE 12-14 Checking the Location capability.
The app obtains the location information from the GPS sensor, if one is available on the device.
If not, the component infers the user's location information from the IP address that connects the
device to the Internet.
reading geographical position
The code you need to query the location subsystem is shown below. You can copy the following
listing straight into the main application JavaScript file for the project, called latlong.js .
var latLongApp = latLongApp || {};
var geolocator = null;
latLongApp.init = function () {
document.getElementById("buttonLocation")
.addEventListener("click", latLongApp.getPosition);
}
latLongApp.getPosition = function () {
geolocator = new Windows.Devices.Geolocation.Geolocator();
var position = geolocator.getGeopositionAsync().then(latLongApp.display,
latLongApp.error);
}
After you have a reference to the geolocation system component, you simply run a query using
the getGeopositionAsync method. As usual, the method works asynchronously and sets up a promise
Search WWH ::




Custom Search