开发者

How to get current location latitude and longitude periodically .

开发者 https://www.devze.com 2023-04-01 01:18 出处:网络
In my application uses current location lat,long. which is periodically update in every 5min. and run in background,means when i launch my application a pop up comes and ask for \"do you want to use c

In my application uses current location lat,long. which is periodically update in every 5min. and run in background,means when i launch my application a pop up comes and ask for "do you want to use current locatio开发者_C百科n" if i press "yes" then service will be run on background of application and use current location lat long,means refreshing in every 5 min,so how to do it.How to make such service.

Please explain in detail as i am new in android . every help would be appreciated thanks in advance


Handling location updates in user-friendly and power-efficient way is no trivial task.

I highly recommend you read Reto Meier's A Deep Dive Into Location (and the second part).

Update

There is a simple (and wrong) way to do it: set AlarmManager to wake your service every 5 min which requests the location.

This is wrong for several reasons. To do it right first answer yourself this questions:

  1. Do you need location updates exactly every 5 minutes?
  2. Even if your app is not active?
  3. Even if phone is in sleep mode?
  4. Even if phone is not moving for longer period (e.g. user is sleeping)?
  5. What accuracy do you need? 10m or 300m?
  6. Do you need GPS accuracy on all locations? GPS drains battery in matter of hours.
  7. Do you need updates if user is moving fast? 5 min in a car can mean 10 miles easily.
0

精彩评论

暂无评论...
验证码 换一张
取 消