Android获取位置并将其发送到服务器

时间:2015-08-14 05:36:05

标签: android gps

要求:

  1. 应用程序必须接收GPS坐标,即使所有活动都已停止(在后台)。
  2. 应用程序应该从API获取数据并每隔几秒使用GPS坐标作为参数(GET http://someserver?lat=xxx&lng=yyy)。这只需要两个活动(MainActivity和MapActivity)。
    1. 应用程序应每隔几秒发布一次坐标(在所有活动中)。
  3. 我如何在android上解决这个任务? 我的方法是:

    1. 使用属性Location location创建单身用户。
    2. 在MainActivity中创建LocationListener并通过onLocationChanged回调中的requestLocationUpdates设置User.getInstance()。location。
    3. 在MainActivity中,我通过Runnable每隔几秒从服务器获取数据:service.getData(User.getInstance().location.getLatitude(), User.getInstance().location.getLongitude, callback)(例如:https://stackoverflow.com/a/6242292/2568343
    4. 与MapActivity中的3相同
    5. 我创建Service并在其内部发布User.getInstance()的坐标。服务器上的位置也是每隔几秒就通过Runnable
    6. 我的问题:

      1. 这是一个好方法吗?
      2. 是否可以很好地利用单身人士来保存坐标?
      3. Runnable是否可以选择间隔提取/从服务器发送数据?
      4. 在MainActivity中创建的LocationListener是否适用于该应用的所有活动和服务?

0 个答案:

没有答案
相关问题