我正在开发应用程序,我需要location
在每个1 minute
特定的device/user
.
假设如果用户在应用程序打开时正在移动,那么他的坐标应该在每个1 minute
. 因此,我有我的 Web 服务设置,可以将数据插入 MySql 数据库。我已经在插入部分测试了我的 WebService,它工作正常。
但我遇到的问题是 - 我不认为它会在每个1 minute
. 谁能告诉我为什么每次都没有发生1 minute
?如果下面的代码有任何问题,任何人都可以通过提供一些示例来帮助我解决上述问题吗?
任何想法都会有很大帮助。
private final String id = UUID.randomUUID().toString();
private final String sampleURL = ServerInfo.getServiceURL() + "/insert";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new GPSLocationListener();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
60000,
0,
this.locationListener);
}
下面是实现的类LocationListener
。
private class GPSLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
if (location != null) {
GeoPoint point = new GeoPoint(
(int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
}
// Below code is used to insert into database
String userId = id;
String mLatitude = Double.toString(location.getLatitude());
String mLongitude = Double.toString(location.getLongitude());
String mProvider = location.getProvider();
String mHasAltitude = Boolean.toString(location.hasAltitude());
String mAltitude = Double.toString(location.getAltitude());
String mHasSpeed = Boolean.toString(location.hasSpeed());
String mSpeed = Float.toString(location.getSpeed());
String mHasBearing = Boolean.toString(location.hasBearing());
String mBearing = Float.toString(location.getBearing());
String mHasAccuracy = Boolean.toString(location.hasAccuracy());
String mAccuracy = Float.toString(location.getAccuracy());
WebServiceTask wst = new WebServiceTask(WebServiceTask.POST_TASK,
getApplicationContext(), "Posting data...");
wst.addNameValuePair("user_id", userId);
wst.addNameValuePair("mlatitude", mLatitude);
wst.addNameValuePair("mlogitude", mLongitude);
wst.addNameValuePair("mprovider", mProvider);
wst.addNameValuePair("mhasAltitude", mHasAltitude);
wst.addNameValuePair("mAltitude", mAltitude);
wst.addNameValuePair("mhasspeed", mHasSpeed);
wst.addNameValuePair("mspeed", mSpeed);
wst.addNameValuePair("mhasbearing", mHasBearing);
wst.addNameValuePair("mbearing", mBearing);
wst.addNameValuePair("mhasaccuracy", mHasAccuracy);
wst.addNameValuePair("maccuracy", mAccuracy);
// This will insert into database
wst.execute(new String[] { sampleURL });
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
注意: - 它正在插入数据库,但它没有完全或大约在我需要的时间间隔内插入1 minute