Android融合位置不会提供定期更新 [英] Android Fused Location Won't Deliver Periodic Updates

查看:102
本文介绍了Android融合位置不会提供定期更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每隔几分钟就获得一次硬性位置修复&每隔几分钟便会进行一次软定位,如果用户移动的距离超过了某些仪表.我正在通过以下代码遍历测试逻辑(在行驶时也使用较大的参数进行了尝试),但它并没有真正返回我定期的位置修复.当请求开始时,它将立即返回位置定位,然后几分钟后有时返回1个位置定位,但是长达一个小时,它不会返回位置定位.

I want to get a hard location fix every certain minutes & a soft location fix every certain minutes and if user has moved more then certain meters. I been testing the logic with following piece of code walking (tried it with larger parameters as well while driving) but it doesn't really return me periodic location fixes. It would return a location fix right away when request starts then sometime return 1 location fix few minutes later that but then for up-to an hour it won't return a location fix.

LocationRequest locationRequest = LocationRequest.create();
int priority = PRIORITY_BALANCED_POWER_ACCURACY;
locationRequest.setPriority(priority);
locationRequest.setInterval(localInterval); //set to 6 minutes
locationRequest.setFastestInterval(localFastestInterval); //set to 3 minutes
locationRequest.setSmallestDisplacement(smallestDisplacement); //set to 10 meters
locationRequest.setNumUpdates(numUpdates);  //set to Int.MAX_VALUE
locationRequest.setExpirationDuration(expirationDuration); // set to Long.MAX_VALUE
LocationServices.FusedLocationApi.requestLocationUpdates(locationClient, locationRequest, pendingIntent);

如果我将位移设置为0,那么我会得到周期性的位置更新.知道发生了什么吗?

If I set displacement to 0 then I get periodic location updates. Any idea what is going on?

推荐答案

经过长期详尽的测试&实验我发现,如果您不调用setFastestInterval,则将完全按照setInterval设置的间隔进行定期更新.

After long exhaustive testing & experimentation I've found that if you don't call setFastestInterval you will get periodic updates exactly according to the interval set with setInterval.

但是,由于其他应用程序可能导致向您快速交付位置定位信息,因此只需检查一下,以忽略超过特定时间阈值的速度而提供的位置定位信息.

However as other applications can cause location fixes to be delivered very fast to you so just put a check for ignoring location fixes delivered faster than a certain threshold of time passed.

根据文档:如果将setFastestInterval(long)设置为比setInterval(long)慢,则您的有效最快间隔是setInterval(long),但这不会发生:设置以下参数应该每隔1分钟为您进行一次硬位置修复,但不会(至少在棉花糖上):

According to documentation: If setFastestInterval(long) is set slower than setInterval(long), then your effective fastest interval is setInterval(long) but that doesn’t happen: e.g. setting following parameters should give you a hard location fix every 1 minute but it does not (on Marshmallow at-least):

interval = 1 min
fastestInterval = 20 min
displacement = 0

如果有人可以用一段很棒的代码来反驳我的发现.

If anyone can disprove my findings with a piece of code that would be great.

这篇关于Android融合位置不会提供定期更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆