2011-08-21 147 views
0

我想显示从SQLite数据库检索到的一些点/坐标。奇怪的是,当我启动地图活动时,我将标记显示在加蓬和尼日利亚附近海域的一个陌生地点:http://imageshack.us/f/402/gabond.png/谷歌地图标记显示在错误的地方

我试图手动设置地图,以便在给定坐标上居中并始终一样的问题。还有一两件事,我有启动活动时,此logcat的错误:

08-21 13:19:59.326: ERROR/MapActivity(404): Couldn't get connection factory client 

代码:

CoordBD CoordBd = new CoordBD(this); 
     CoordBd.open(); 

     Coordo coordo = new Coordo(36.876673,10.325928); 
     Coordo coordo2 = new Coordo(36.876982,10.326228); 
     //CoordBd.open(); 
     CoordBd.insertCoordo(coordo); 
     CoordBd.insertCoordo(coordo2); 
     // CoordBd.close(); 

     maMap = (MapView)findViewById(R.id.myGmap); 
     maMap.setBuiltInZoomControls(true); 
     ItemizedOverlayPerso pinOverlay = new ItemizedOverlayPerso(getResources().getDrawable(R.drawable.marker)); 

     /*db = openOrCreateDatabase(
      "coord.bd" 
      , SQLiteDatabase.CREATE_IF_NECESSARY 
      , null 
      ); 
     db.setVersion(1); 
     db.setLocale(Locale.getDefault()); 
     db.setLockingEnabled(true);*/ 

     String[] result_columns = new String[] {COL_LATI, COL_LONGI}; 
     Cursor cur = db.query(true, TABLE_COORD, result_columns, 
     null, null, null, null, null, null); 
     cur.moveToFirst(); 
     while (cur.isAfterLast() == false) { 
      int latitude = cur.getColumnIndex("latitude"); 
      int longitude = cur.getColumnIndex("longitude"); 
      point = new GeoPoint(microdegrees(latitude),microdegrees(longitude)); 
      pinOverlay.addPoint(point); 
      cur.moveToNext(); 
     } 
     cur.close(); 
     CoordBd.close(); 

     maMap.getOverlays().add(pinOverlay); 
     monControler = maMap.getController(); 
     monControler.setZoom(12); 
     monControler.setCenter(point); 

     LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, this); 

可能是什么问题的根源? PS:我在手机上安装应用程序时遇到同样的问题。 谢谢你的帮助。 编辑:logcat的:(后大呼过瘾答案修改它):

08-22 01:55:35.381: ERROR/AndroidRuntime(253): Uncaught handler: thread main exiting due to uncaught exception 
08-22 01:55:35.402: ERROR/AndroidRuntime(253): java.lang.RuntimeException: Unable to start activity ComponentInfo{carburant.android.com/carburant.android.com.Geo}: java.lang.IllegalStateException: get field slot from row 0 col -1 failed 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.app.ActivityThread.access$2200(ActivityThread.java:119) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.os.Handler.dispatchMessage(Handler.java:99) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.os.Looper.loop(Looper.java:123) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.app.ActivityThread.main(ActivityThread.java:4363) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at java.lang.reflect.Method.invokeNative(Native Method) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at java.lang.reflect.Method.invoke(Method.java:521) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at dalvik.system.NativeStart.main(Native Method) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253): Caused by: java.lang.IllegalStateException: get field slot from row 0 col -1 failed 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.database.CursorWindow.getDouble_native(Native Method) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.database.CursorWindow.getDouble(CursorWindow.java:399) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.database.AbstractWindowedCursor.getDouble(AbstractWindowedCursor.java:138) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at carburant.android.com.Geo.onCreate(Geo.java:92) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 
08-22 01:55:35.402: ERROR/AndroidRuntime(253):  ... 11 more 

EDIT: Added class creating the DB: 

public class MaBaseSQLite extends SQLiteOpenHelper { 
private static final String CREATE_BDD = "CREATE TABLE " + TABLE_COORD + " (" 
    + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_LATI + " TEXT NOT NULL, " 
    + COL_LONGI + " TEXT NOT NULL);"; 

    MaBaseSQLite(Context context) { 
     super(context, DATABASE_NAME, null, DATABASE_VERSION); 
    } 

    @Override 
    public void onCreate(SQLiteDatabase db) { 
     //on créé la table à partir de la requête écrite dans la variable CREATE_BDD 
     db.execSQL(CREATE_BDD); 
    } 
+0

原因你得到这一点存在是因为你的坐标是被设置为0,0,这在图中提供,即地球上的0,0点。我会看看代码,看看我能否找到问题。 – hooked82

回答

2

在while循环设置一个断点,你可能会发现,经度和纬度都为0,或者0和1。问题在于以下两行。你得到的是列索引,而不是实际值。您还需要保存你的坐标为双打而不是整数:

int latitude = cur.getColumnIndex("latitude"); 
int longitude = cur.getColumnIndex("longitude"); 

尝试将其设置为:

double latitude = cur.getDouble(cur.getColumnIndex("latitude")); 
double longitude = cur.getDouble(cur.getColumnIndex("longitude")); 
+0

谢谢你的回答。我现在正在使用这个代码片段,而不是旧的代码片段,我正在获得一个FC。请看我编辑的帖子。 – androniennn

+0

这是什么错误? '从第0行col-1失败'获得字段插槽 – androniennn

+0

堆栈跟踪中的错误是说你试图访问的列名在光标中不可用。您需要发布表创建代码,以便我们可以看到您的列名以及返回您的游标对象的代码。另外,请尝试getColumnIndexOrThrow(COLUMN_NAME)以获得更好的错误消息。 – hooked82