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

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

问题描述

我想每隔几分钟就进行一次硬定位每隔特定分钟修复一次软位置,如果用户移动了超过特定米.我一直在使用以下代码行走测试逻辑(在驾驶时也尝试使用更大的参数),但它并没有真正返回我的定期位置修复.它会在请求开始时立即返回一个位置修复,然后有时在几分钟后返回 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)em> 但这不会发生:例如设置以下参数应该每 1 分钟给你一个硬定位,但它没有(至少在 Marshmallow 上):

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 Fused Location 不会提供定期更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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