当前位置纬度经度如何定期更新

时间:2011-09-16 07:03:18

标签: android

我是android新手。我想将纬度经度发送到Web服务,该服务定期以15分钟的时间间隔更新。即使我的设备处于快速模式。即使我的应用程序未激活。即使手机长时间没有移动。即使用户移动速度很快。提前致谢。

2 个答案:

答案 0 :(得分:2)

这是你需要的;)

http://developer.android.com/guide/topics/location/obtaining-user-location.html

该页面代码中的此行设置更新率。

    // Register the listener with the Location Manager to receive location updates
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

这是关于它如何运作的更多信息

    http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(java.lang.String, long, float, android.app.PendingIntent)

但请记住,在不需要时停止位置更新,电池电量很重

答案 1 :(得分:1)

好的,

1.Lets start from the first, "periodically update at time interval of 15 minute"
->for this we already suggest you to use service and timer or alarm manager.

2. "Even if my device is in spleep mode".
-> For this you prevent to going your device in sleep mode for that you can use android's WAKE_LOCK. 

3. "Even if my application is not active".
-> I think for this, you can start a service at the device boot time, and it is countinuesly going to run..

4. "Even if phone is not moving for long period.Even if user is moving fast".
-> for this from service save your lat,long at every 15 minutes and also check whether
   location is updated or not if updated then just update your lat,long also, and then just
   send the lat, long for every 15 minutes.

希望你能理解,谢谢,