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?
该应用程序基于GPS跟踪,其中必须定期发送纬度和经度坐标。目前我们通过DDMS手动输入坐标。发送数据一直是个问题。那么,你们中有人有什么建议吗?
2 个解决方案
#1
0
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,它从android扩展Application类并在android清单中设置它,在AC创建字段位置和在onLocationChanged(位置位置)中创建的函数将保存AC中的新位置而不是使用TimerTask进行频率调整它应该多久从AC获取位置并将其发送到您想要的任何地方。
ApplicationController will keep all information as long as application is "alive" in that class you have to also create accessors ;) sample code below:
只要应用程序在该类中“活动”,ApplicationController将保留所有信息,您还必须创建访问器;)示例代码如下:
ApplicationController.java
import android.app.Application;
import android.location.Location;
public class ApplicationController extends Application{
private Location location = null;
@Override
public void onCreate() {
super.onCreate();
}
public void setLocation(Location location){
this.location = location;
}
public Location getLocation(){
return location;
}
}
Entry in android manifest:
在android清单中输入:
<application
android:label="@string/app_name"
android:allowClearUserData="false" android:name="core.ApplicationController"
android:icon="@drawable/driving">
Sample use in code:
代码中的示例使用:
AC = (ApplicationController) getApplicationContext();
private void initializeGpsTask(long frequency){
gpsTask = new TimerTask() {
@Override
public void run() {
Log.i(TAG, "GPS TASK");
if(AC.getLocation()!=null){
insertIntoDatabase(transactions.generateRequest(
AC.getLocation()));
}
}
};
Timer timer = new Timer();
timer.schedule(gpsTask, frequency, frequency);-
}
That might be helpful LINK
这可能是有用的LINK
#2
0
You have to implement locationListener class to listen the location
您必须实现locationListener类来侦听位置
onLocationChanged(Location location) {
lat = location.getLatitude();
lon = location.getLongitude(0;
}
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.
现在,当您获得纬度和经度时,您必须定期将其发送到服务器。您可以使用该服务从后台侦听位置信息,如果您获得onLocationChanged事件,则建立与Web服务的http连接并将经度和纬度发布到服务器。
#1
0
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,它从android扩展Application类并在android清单中设置它,在AC创建字段位置和在onLocationChanged(位置位置)中创建的函数将保存AC中的新位置而不是使用TimerTask进行频率调整它应该多久从AC获取位置并将其发送到您想要的任何地方。
ApplicationController will keep all information as long as application is "alive" in that class you have to also create accessors ;) sample code below:
只要应用程序在该类中“活动”,ApplicationController将保留所有信息,您还必须创建访问器;)示例代码如下:
ApplicationController.java
import android.app.Application;
import android.location.Location;
public class ApplicationController extends Application{
private Location location = null;
@Override
public void onCreate() {
super.onCreate();
}
public void setLocation(Location location){
this.location = location;
}
public Location getLocation(){
return location;
}
}
Entry in android manifest:
在android清单中输入:
<application
android:label="@string/app_name"
android:allowClearUserData="false" android:name="core.ApplicationController"
android:icon="@drawable/driving">
Sample use in code:
代码中的示例使用:
AC = (ApplicationController) getApplicationContext();
private void initializeGpsTask(long frequency){
gpsTask = new TimerTask() {
@Override
public void run() {
Log.i(TAG, "GPS TASK");
if(AC.getLocation()!=null){
insertIntoDatabase(transactions.generateRequest(
AC.getLocation()));
}
}
};
Timer timer = new Timer();
timer.schedule(gpsTask, frequency, frequency);-
}
That might be helpful LINK
这可能是有用的LINK
#2
0
You have to implement locationListener class to listen the location
您必须实现locationListener类来侦听位置
onLocationChanged(Location location) {
lat = location.getLatitude();
lon = location.getLongitude(0;
}
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.
现在,当您获得纬度和经度时,您必须定期将其发送到服务器。您可以使用该服务从后台侦听位置信息,如果您获得onLocationChanged事件,则建立与Web服务的http连接并将经度和纬度发布到服务器。