how to update user location in both foreground and background every 10 seconds? [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-14 04:15:08

问题


I'm making a location tracking app. In this app, I need to record user location every 10 seconds. Also, the recording is done in a background service so that the application does not need to be in foreground. To make this, I tried to use Timer but it's not working in background. I've tried so much but it didn't work. Could you help me please?

I found this great tutorial: https://www.raywenderlich.com/5817-background-modes-tutorial-getting-started


回答1:


I had a similar app to be built some time ago, and I also tried things like you did, but that is very very wrong way to use timer and all to record your location.

First of all, I suggest you to not try to record/ping location explicitly because, it will cause batter drainage. There is something called, significant location change, please go through it in docs. This will trigger you location update in every single significant location change.

But I assume, you really need to ping the location. There is a git repo, link below

Background geo location tracking

Please go though it, it is really nice library out there, I have ever come across, go through its documents. I am sure you will come around and be able to use it for your app. :)



来源:https://stackoverflow.com/questions/53595690/how-to-update-user-location-in-both-foreground-and-background-every-10-seconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!