【问题标题】:Is there a method only retrieve location coordinates when there is a change有没有一种方法只在发生变化时检索位置坐标
【发布时间】:2019-02-17 17:50:09
【问题描述】:

以下方法用于开始和停止位置跟踪,使用我的应用程序几乎每分钟连续轮询位置。我只想在坐标发生变化时捕获该位置。我想知道有什么方法可以在发生变化时进行比较和检索位置。 我试图手动比较使请求变慢的坐标。请指教。

public void stopTracking() {
        if (time != null) {
            time.cancel();
        }
        time = null;
        LocationManager.getLocationManager().setLocationListener(null);
    }

    public void startTracking() {
        if (time != null) {
            stopTracking();
        }
        if (Preferences.get("LocationTracking", true)) {
            long delay = Server.instance.getLoctionPollingIntervalMillis();
            LocationManager.getLocationManager().setLocationListener(this,
                    new LocationRequest(LocationRequest.PRIORITY_LOW_ACCUARCY, delay));
            time = new Timer();
            time.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (lastLocation != null) {
                        double lat = (double) lastLocation.getLatitude();
                        double lot = (double) lastLocation.getLongitude();
                        Server.instance.updateLocationInServer(lat, lot, System.currentTimeMillis(), true);
                    }
                }
            }, 30000, delay);
        }
    }

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    删除计时器代码并将服务器更新写入由侦听器调用的LocationRequest 类。我还建议添加一个更新阈值,因为某些实现可以以非常高的频率和非常好的移动更新您。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多