简体   繁体   English

使用fusedLocation API定期发送位置更新

[英]periodically send location updates using fusedLocation API

Android programming is a brand new thing to me, i've been playing with android's location and i have a same issue, im going to send a periodic location updates to a server in background and i'm using the AlarmManager/LocationManager approach, set an alarmManager with a defined Interval then when the alarmReceiver is triggered it will get device's current location (using locationManager) and send it to the server on its onReceive method. Android编程对我来说是一种崭新的事物,我一直在使用android的位置,并且遇到了相同的问题,我将在后台向服务器发送定期的位置更新,并且我正在使用AlarmManager / LocationManager方法,一个具有定义的时间间隔的alarmManager,然后在触发alarmReceiver时,它将获取设备的当前位置(使用locationManager)并将其通过onReceive方法发送到服务器。 i found out this FusedLocation as a great replacement as LocationManager give me an additional job to get the best location provider. 我发现这个FusedLocation是一个很好的替代品,因为LocationManager给了我额外的工作来获得最佳的位置提供者。 is it possible to perform sending location updates in background periodically using fusedLocation api without an alarmManager? 是否可以在不使用alarmManager的情况下使用熔融位置api在后台定期发送位置更新? if so, how can i do that? 如果是这样,我该怎么办? thanks in advance! 提前致谢!

Per the LocationRequest documentation : 根据LocationRequest文档

In between these two extremes is a very common use-case, where applications definitely want to receive updates at a specified interval, and can receive them faster when available, but still want a low power impact. 在这两种极端之间,是一个非常常见的用例,应用程序肯定希望在指定的时间间隔内接收更新,并且可以在可用时更快地接收更新,但仍然希望降低功耗。 These applications should consider PRIORITY_BALANCED_POWER_ACCURACY combined with a faster setFastestInterval(long) (such as 1 minute) and a slower setInterval(long) (such as 60 minutes). 这些应用程序应考虑将PRIORITY_BALANCED_POWER_ACCURACY与更快的setFastestInterval(long) (例如1分钟)和较慢的setInterval(long) (例如60分钟)结合使用。 They will only be assigned power blame for the interval set by setInterval(long) , but can still receive locations triggered by other applications at a rate up to setFastestInterval(long) . 仅会为setInterval(long)设置的时间间隔分配责任,但仍可以以setFastestInterval(long)的速率接收其他应用程序触发的位置。 This style of request is appropriate for many location aware applications, including background usage. 这种类型的请求适用于许多支持位置的应用程序,包括后台使用情况。 Do be careful to also throttle setFastestInterval(long) if you perform heavy-weight work after receiving an update - such as using the network. 如果在收到更新(例如使用网络)后执行繁重的工作,请也要节制setFastestInterval(long)

This allows you to guarantee you'll get location updates based on the interval you set with setInterval(long) , giving you the equivalent behavior to a periodic alarm, but if other apps request location information, you may get location information as often as your setFastestInterval(long) - you can set your fastest interval to your interval if you just want location updates at a set interval. 这可以确保您将根据使用setInterval(long)设置的间隔来获取位置更新,从而为您提供与定期警报相同的行为,但是如果其他应用程序请求位置信息,则您获得的位置信息的频率与setFastestInterval(long) -如果只想按设置的间隔更新位置,则可以将最快的间隔设置为间隔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM