2013-07-12 99 views
0

我有一個sqlite數據庫tre列: id,緯度,經度。 經度和緯度是雙倍和43.98722。 當我複製這個數據庫中的經度和緯度的Android設備值成爲4.398722e + 07 所以這也許不工作我的應用程序。 我該如何解決這個問題? 也許這是我的dbhelper複製一個外部數據庫通過InputStream和OutputStream,使這個錯誤?通過數據庫sqlite更改緯度和經度的值android

+0

什麼類型的列? – njzk2

+0

是雙倍的,這是問題所在? – tafazzi87

+0

還,定義'這也許並不work' – njzk2

回答

0
public class MyOpenHelper extends SQLiteOpenHelper{ 


private static String DB_PATH = "/data/data/pack.pullman/databases/"; 

private static String DB_NAME = "orari"; 

private SQLiteDatabase myDataBase; 

private final Context myContext; 


public MyOpenHelper(Context context) { 
    super(context, DB_NAME, null, 1); 
    if(android.os.Build.VERSION.SDK_INT >= 4.2){ 
     DB_PATH = context.getApplicationInfo().dataDir + "/databases/";   
    } else { 
     DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; 
    } 
    this.myContext = context; 
} 

public void createDataBase() throws IOException{ 

    boolean dbExist = checkDataBase(); 

    if(dbExist){ 

    }else{ 

     this.getReadableDatabase(); 

     try { 

      copyDataBase(); 


     } catch (IOException e) { 

      throw new Error("Error copying database"); 

     } 
    } 

} 


private boolean checkDataBase(){ 

    SQLiteDatabase checkDB = null; 

    try{ 
     String myPath = DB_PATH + DB_NAME; 
     checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE); 

    }catch(SQLiteException e){ 


    } 

    if(checkDB != null){ 

     checkDB.close(); 

    } 

    return checkDB != null ? true : false; 
} 


private void copyDataBase() throws IOException{ 

    InputStream myInput = myContext.getAssets().open(DB_NAME); 

    String outFileName = DB_PATH + DB_NAME; 

    OutputStream myOutput = new FileOutputStream(outFileName); 

    byte[] buffer = new byte[1024]; 
    int length; 
    while ((length = myInput.read(buffer))>0){ 
     myOutput.write(buffer, 0, length); 
    } 

    //Close the streams 
    myOutput.flush(); 
    myOutput.close(); 
    myInput.close(); 

} 

public void openDataBase() throws SQLException{ 

    //Open the database 
    String myPath = DB_PATH + DB_NAME; 
    myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE); 


} 

@Override 
public synchronized void close() { 

     if(myDataBase != null) 
      myDataBase.close(); 

     super.close(); 

} 
@Override 
public void onCreate(SQLiteDatabase db) { 
    // TODO Auto-generated method stub 

} 

@Override 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
    // TODO Auto-generated method stub 

} 

    } 
0
public List<Coordinate> vediCoordinate(){ 
    SQLiteDatabase db=oh.getReadableDatabase(); 
    String c[]=new String[]{"lat","long","via"}; 
    cu=db.query("linee", c, null, null, null, null, null); 
    int rows=cu.getCount(); 
    LinkedList<Coordinate> risultato=new LinkedList<Coordinate>(); 
    cu.moveToFirst(); 
    for(int i=0;i<rows;i++){ 
     risultato.add(i,new Coordinate(cu.getDouble(cu.getColumnIndex("lat")),cu.getDouble(cu.getColumnIndex("long")),cu.getString(cu.getColumnIndex("via")))); 
     cu.moveToNext(); 
    } 
    cu.close(); 
    return risultato; 
}