我想将我的位置发送到我的数据库中。我有这样的代码来获取位置(经度和纬度)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
//Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(null);
locationManager.requestLocationUpdates(provider, 2000, 10,
locationListener);
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
public void onProviderEnabled(String provider){ }
public void onStatusChanged(String provider, int status,
Bundle extras){ }
};
private void updateWithNewLocation(Location location) {
//EditText etlat=(EditText)findViewById(R.id.lat);
//EditText etlong=(EditText)findViewById(R.id.lng);
if (location != null) {
double lat = location.getLatitude();
System.out.println(lat);
double lng = location.getLongitude();
System.out.println(lng);
double alt = location.getAltitude();
System.out.println(alt);
etlat.setText(String.valueOf(lat));
etlng.setText(String.valueOf(lng));
etalt.setText(String.valueOf(alt));
}
}
然后我想将我的位置保存到数据库中,间隔 10 分钟..
我该怎么做?谢谢 :)