I am currently working on an Android app using Worklight.
I am not able to understand how to implement geolocation and how to call it from HTML button event.
I am currently working on an Android app using Worklight.
I am not able to understand how to implement geolocation and how to call it from HTML button event.
Worklight 6.0 added Location Services APIs that go beyond the w3c geolocation APIs available in the navigator.geolocation
object. To sum it up, they allow you to:
As of 6.1 this is available also as native APIs for iOS and Android. We've also added some cool features that allow you to conveniently debug and test location-based hybrid (javascript) apps - see here.
Take a look at the Apache Cordova documentation here and follow the examples. Under Advanced Topics read the Location Services PDF and Example Code here. There's also documentation in IBM Information Center here and API documentation here.
Quick example, run on a real device with the GPS turned on:
index.html
<button onclick="alertGeo()">Click to alert GPS info.</button>
main.js
function alertGeo() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
function onSuccess(position) {
alert(JSON.stringify(position));
}
function onError(error) {
alert(JSON.stringify(error));
}
}