如何使用 JSON 定期向 Web 服务器发送两个参数?
该应用程序基于 GPS 跟踪,必须定期发送纬度和经度坐标。目前,我们通过 DDMS 手动输入坐标。发送数据一直是一个很大的问题。那么,你们有什么建议吗?
The application is based on GPS tracking where the latitude and longitude co-ordinates have to be sent at regular intervals. For now we are manually entering the co-ordinates through DDMS. Sending the data has been quite a problem. So, do any of you have some suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你必须存储某个位置,所以创建ApplicationController,它从android扩展Application类,并将其设置在android清单中,在AC中创建字段Location并在onLocationChanged(Location location)中创建函数,该函数将在AC中保存新位置,而不是按频率创建TimerTask它应该多久从 AC 获取位置并将其发送到您想要的任何地方。
只要应用程序在该类中“活动”,ApplicationController 就会保留所有信息,您还必须创建访问器;)下面的示例代码:
ApplicationController.java
Android 清单中的条目:
代码中的示例使用:
这可能会有所帮助 链接
I think you have to store somewhere location so create ApplicationController which extends Application class from android and set it in android manifest, in AC create field Location and in onLocationChanged(Location location) made function which will save new location in AC than made TimerTask with frequency how often it should get location from AC and send it wherever you want.
ApplicationController will keep all information as long as application is "alive" in that class you have to also create accessors ;) sample code below:
ApplicationController.java
Entry in android manifest:
Sample use in code:
That might be helpful LINK
您必须实现 locationListener 类来侦听位置
现在,当您获得纬度和经度时,您必须定期将其发送到服务器。
您可以使用该服务从后台监听位置信息,如果您收到
onLocationChanged
事件,则与您的 Web 服务建立 http 连接并将纬度和经度发布到服务器。You have to implement locationListener class to listen the location
Now when you get the latitude and longitude you will have to sent it to the server at regular interval.
You can use the service to listen the location information from background and if you got the
onLocationChanged
event make a http connection to your web service and post the latitude and longitude to the server.