开发者

Google Maps marker shown in the wrong place

I want to show some points/coordinates retrieved from an SQLite databse. The weird thing that when I launch map activity I have the marker shown on a strange place, in the sea, near to Gabon and Nigeria: http://imageshack.us/f/402/gabond.png/

I tried to set manually the map to be centered on a given coordinates and always the same problem. One other thing, I have this logcat error when launching the activity:

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

Code:

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);
        I开发者_Go百科temizedOverlayPerso 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);

What could be the source of the problem? PS: I have the same problem when installing the app on the phone. Thank you for your help. EDIT: Logcat: (after modifying it with hooked answer):

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);
    }


Set a breakpoint in your while loop and you'll probably notice that latitude and longitude are both 0, or 0 and 1. The problem is with the following two lines. You're getting the column index, not actual values. You'll also want to store your co-ordinates as doubles rather than integers:

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

try setting it to:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜