Ionic: background geolocation

空扰寡人 提交于 2021-02-11 06:22:58

问题


I'm using Ionic & Firebase to create an Android application for geolocation. I used ngCordova.geolocation and I successfully get the device current location.

My problem is that I need to continuously get current location, as long as the user doesn't turn off geolocation and callback a function every time the geolocation change, and test if the user is inside one of many circles in the maps.


回答1:


Since you are already using the ngcordova.geolocation plugin, it has a method to keep tracking the device position via watchPosition. There's an example in the docs indicating how to use it:

  var watchOptions = {
    timeout : 3000,
    enableHighAccuracy: false // may cause errors if true
  };

  var watch = $cordovaGeolocation.watchPosition(watchOptions);
  watch.then(
    null,
    function(err) {
      // error
    },
    function(position) {
      var lat  = position.coords.latitude
      var long = position.coords.longitude

      /* Further code to execute on each update */
  });


来源:https://stackoverflow.com/questions/38994343/ionic-background-geolocation

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