我正在尝试获取设备的位置并不断更新到数据库...但是我只想在后台运行该过程并将位置更新到Web服务器中的数据库
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.makeUseOfNewLocation(location);
double latitude=location.getLatitude();
givenlatitude=String.valueOf(latitude);
double longitude=location.getLongitude();
Toast.makeText(getApplicationContext(),String.valueOf(latitude)+ " " +String.valueOf(longitude) , Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, 1.0f, locationListener);
`
这就是我在间隔时间获取位置的方式...我只想在后台运行此代码并将其更新到数据库中!