Tracking user location

天涯浪子 提交于 2019-12-14 04:21:36

问题


Problem:

The user can choose how long and when start to track your locaton (Like today from 08:00 to 16:00). So during this interval my application will listen for the location every 5 minutes (this time can be changed, it's a user's preference).

What I'm thinking:

Making a service to be running and listenning for coming of the GPS or network locations during the time interval definned by the user.

Problem:

The service can be removed for running a long time?

I need to registers listeners to GPS and Network (even if they have not enabled) when starting the service or I need to register and remove Listener depending status of GPS and Network?

My service will continue running even if the user is not using the phone for a long time (like an hour) right?


回答1:


You don't need to register a Service for this. You can use Mak Murphy's cwac-locpoll library.

This is a short description of the library taken from the page linked above. You'll also find code examples there.

You simply set up an AlarmManager alarm to contact LocationPoller on whatever frequency you wish, and it will handle all of the location work from there, sending you the results via a broadcast Intent. Your BroadcastReceiver can then use the location data as needed.



来源:https://stackoverflow.com/questions/13219285/tracking-user-location

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