简体   繁体   English

在后台服务中获取位置更新 - Android Studio

[英]Get Location Updates in Background Service - Android Studio

after researching the Android Location FusedLocationProviderClient I am very confused about what you should and should not do!在研究了 Android Location FusedLocationProviderClient 之后,我对您应该做什么和不应该做什么感到非常困惑!

The use case is: The App holds different locations with latitude and longitude.用例是:应用程序保存不同的经纬度位置。 While the user is walking around the app (with the phone in the pocket, screen off) needs to track if he is close to one of the locations and plays a short beep when closer than a defined range.当用户在应用程序周围走动时(手机放在口袋里,屏幕关闭)需要跟踪他是否靠近其中一个位置,并在比定义的范围更近时播放短促的哔哔声。

Would the Geofence option the best solution?地理围栏选项是最佳解决方案吗? These locations will also change during runtime and periodically - they might also be more than 100. Any suggestion?这些位置也会在运行时定期更改 - 它们也可能超过 100 个。有什么建议吗?

I am also thinking about a background service to handle all this when the device moves.我也在考虑在设备移动时处理所有这些的后台服务。 This would be more flexible and allows for the reload of the locations as well.这将更加灵活,并且还允许重新加载位置。 Any thoughts?有什么想法吗?

Thanks!!谢谢!!

You don't actually need to build a background service to monitor if a user is close to a location.您实际上不需要构建后台服务来监控用户是否靠近某个位置。 There is already a geofence provided by Google.谷歌已经提供了地理围栏。 It uses fusedlocation provider internally.它在内部使用 fusedlocation 提供程序。

Please refer this参考这个

You can combine this with a FusedLocationProviderClient and subscribe to location updates.您可以将其与FusedLocationProviderClient结合使用并订阅位置更新。 This way you'll get location updates as well.这样,您也将获得位置更新。

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

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