如何每 10 秒在前台和后台更新用户位置? [英] how to update user location in both foreground and background every 10 seconds?

查看:39
本文介绍了如何每 10 秒在前台和后台更新用户位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个位置跟踪应用.在这个应用程序中,我需要每 10 秒记录一次用户位置.此外,录制是在后台服务中完成的,因此应用程序不需要在前台.为此,我尝试使用 Timer 但它在后台不起作用.我已经尝试了很多,但没有奏效.你能帮我吗?

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?

我发现了这个很棒的教程:https://www.raywenderlich.com/5817-background-modes-tutorial-getting-started

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

推荐答案

前段时间我有一个类似的应用程序要构建,我也尝试过像你一样的东西,但这是使用计时器和所有的非常非常错误的方式记录您的位置.

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.

首先,我建议您不要尝试明确记录/ping 位置,因为这会导致电池漏电.有一个叫做,显着位置变化的东西,请在文档中仔细阅读.这将在每次重大位置更改时触发您的位置更新.

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.

但我认为,您确实需要 ping 位置.有一个git repo,链接如下

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

背景地理位置跟踪

请去看看,那里是一个非常好的图书馆,我曾经遇到过,浏览过它的文档.我相信你会过来并且能够将它用于你的应用程序.:)

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

这篇关于如何每 10 秒在前台和后台更新用户位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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