how to update user location in both foreground and

2019-09-25 10:50发布

问题:

This question already has an answer here:

  • Update location in Background 1 answer

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. :)