获取Android的GPS定位每隔几分钟一次 [英] Obtain Android GPS location once every few minutes

查看:2232
本文介绍了获取Android的GPS定位每隔几分钟一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个应用程序在Android上载我的GPS定位外部网站每隔约5分钟。这需要有尽可能最小的对电池寿命尽可能产生影响,但它也需要在没有任何用户交互工作。 (背景:我在竞争的铁人三项它会带我大约14小时才能完成,而要广播我在近实时的位置,而无须担心与我的手机摆弄)

I would like to write an app on Android to upload my GPS location to an external website once every ~5 minutes. This needs to have as minimal an impact on battery life as possible, but it also needs to work without any user interaction. (Background: I'm competing in an Ironman triathlon which will take me about 14 hours to complete, and want to broadcast my location in near-real-time but without having to worry about fiddling with my phone.)

所以,我最初的想法是写一个服务,它使用LocationManager.requestLocationUpdates()有5分钟的minTime,但这次竟然唤醒设备,每5分钟为我服务,以完成其工作?

So my initial thought is to write a Service which uses LocationManager.requestLocationUpdates() with a minTime of 5 minutes, but will this actually wake the device up every 5 minutes for my service to do its job?

听起来好像我还需要使用AlarmManager.setInexactRepeating(),以确保当它完成了它的任务,我的服务是清醒的,但如何与requestLocationUpdates那部戏()?我应该代替设置minTime = 0 requestLocationUpdates(),但是回去为获得未来的更新,尽快入睡?

It sounds like I would also need to use AlarmManager.setInexactRepeating() to make sure my service is awake while it completes its task but how does that play with requestLocationUpdates()? Should I instead set minTime=0 on requestLocationUpdates() but then go back to sleep as soon as the next update is obtained?

在如何设计这个任何一般性的指导大大AP preciated。我是一个称职的Java程序员和放大器;将使用谷歌地图的服务器上绘制我的位置,但我pretty的新Android开发,所以我基本上是在寻找一个高层次的计划,就如何构建客户端应用程序。

Any general guidance on how to design this is greatly appreciated. I'm a competent Java programmer & will be using Google Maps on the server to plot my location, but am pretty new to Android development so I'm basically looking for a high-level plan on how to architect the client app.

推荐答案

您服务必须是活着的所有要接收更新的时间。

Your service must be alive all the time you want to receive updates.

<一个href="http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates%28java.lang.String,%20long,%20float,%20android.location.LocationListener%29" rel="nofollow">http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates%28java.lang.String,%20long,%20float,%20android.location.LocationListener%29

您可以告诉你如何经常要被通知的位置变化minTime参数。但是,它没有降低电池消耗。全球定位系统启用,除非你使用removeUpdates方法不管你想要多久接收更新。

You can tell how often you want to be informed of location change with minTime parameter. It does not however decrease battery consumption. GPS is enabled unless you use removeUpdates method no matter how often you want to receive updates.

您可以使用另一种approache:用上述方法启用GPS,读一个值,使用removeUpdates方法,等待5分钟,从头再来。启用和在检索一个位置可以是几秒至数分钟之间延迟

You can use another approache:enable GPS using method above, read one value, use removeUpdates method, wait 5 minutes and all over again. Delay between enabling and retreiving a location can be between few seconds to few minutes.

这篇关于获取Android的GPS定位每隔几分钟一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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