IBM Worklight - How to implement GPS functionality? [closed]

為{幸葍}努か 提交于 2019-12-13 10:39:44

问题


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.


回答1:


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:

  1. Get the current location.
  2. Setup ongoing acquisition policy (desired accuracy, min time and distance between location updates, etc - things that influence the battery consumption).
  3. Setup location-change and geo-fence triggers (exit, enter, dwell inside or outside a polygon or a circle) which can
    1. trigger callback functions and
    2. send semantic location events to the server - which can act upon them using event handlers you register in your adapters.
  4. Do the same also for indoor location using wifi visibility (on Android) and connected wifi (on Android, iOS, and WP8).

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.




回答2:


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));
    }
}


来源:https://stackoverflow.com/questions/21367819/ibm-worklight-how-to-implement-gps-functionality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!