我将这段代码用作位置获取程序,并将其保存在数据库中。 如果我单击查找,它将每10秒提供一次数据。这就是我喜欢做的事;每2秒可以获得一次位置数据吗?
//这是我的代码
locate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location location) {
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude()));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(17);
mMap.clear();
MarkerOptions mp = new MarkerOptions();
mp.position(new LatLng(location.getLatitude(), location.getLongitude()));
mp.title("");
final String lat = Double.toString(location.getLatitude());
final String lon = Double.toString(location.getLongitude());
hidelat.setText(lat);
hidelon.setText(lon);
final String syncPassed = "1";
final String syncNotPassed="0";
final String well = String.valueOf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", java.util.Locale.getDefault()).format(new java.util.Date()));
String gg = Settings.Secure.getString(getApplicationContext().getContentResolver(),
Settings.Secure.ANDROID_ID);
mMap.addMarker(mp);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
DatabaseHelper databaseHelper = new DatabaseHelper(getApplicationContext());
SQLiteDatabase db = databaseHelper.getWritableDatabase();
boolean accepted = databaseHelper.saveLocationToLocalDatabase(lat, lon, well, syncPassed, db);
if (accepted == true)
Log.w("PAKULTIE: ","Location Found");
else
Log.w("PAKULTIE: ","Location Error");
}
});