我有一个GPS位置插入代码,但是它不能插入数据库:
当尝试获取位置时,一切都正常,但插入操作出现问题。我有类似的代码使用了加速度计,那个可以正常工作。请帮助我。
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
final String gps = "CREATE TABLE IF NOT EXISTS GPS_Values ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, Latitude float(10, 6), Longitude float(10, 6), cur_timestamp TIMESTAMP);";
db.execSQL(gps);
还有插入行:
// GPS
public class MyLocationListener implements LocationListener {
public void onLocationChanged(Location loc) {
loc.getLatitude();
loc.getLongitude();
ContentValues gps_values = new ContentValues();
gps_values.put("Latitude", loc.getLatitude());
gps_values.put("Longitutde", loc.getLongitude());
try {
db.beginTransaction();
db.insert("GPS_Values", null, gps_values);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
String Text = "My current location is: " + "Latitude = "
+ loc.getLatitude() + "\nLongitude = " + loc.getLongitude();
Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT)
.show();
}
public void onProviderDisabled(String provider) {
Toast.makeText(getApplicationContext(), "Gps Disabled",
Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String provider) {
Toast.makeText(getApplicationContext(), "Gps Enabled",
Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}// gps vége
当尝试获取位置时,一切都正常,但插入操作出现问题。我有类似的代码使用了加速度计,那个可以正常工作。请帮助我。