Get Geopoints from SQlite DB

半城伤御伤魂 提交于 2020-01-16 15:43:02

问题


I created an SQlite database to store on it all latitudes and longitudes to display them in map. For the add of the values i didn't encouter any problem, i used this code:

CoordBD CoordBd = new CoordBD(this);
Coordo coordo = new Coordo(36.869686,10.315642 );
CoordBd.open();
CoordBd.insertCoordo(coordo);

But i don't know how to insert them one by one in map, i usually/manually make this:

GeoPoint point2 = new GeoPoint(microdegrees(36.86774),microdegrees(10.305302));
pinOverlay.addPoint(point2);

How to browse all the database and add all the Geopoints automatically? Thank you. EDIT: Is that true?

CoordBD CoordBd = new CoordBD(this);
        CoordBd.open();
        Coordo coordo = new Coordo(36.869686,10.315642 );
        CoordBd.insertCoordo(coordo);
        CoordBd.close();

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

        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");
                GeoPoint point = new GeoPoint(microdegrees(latitude),microdegrees(longitude));
                pinOverlay.addPoint(point);
            cur.moveToNext();
        }
        cur.close();

回答1:


Quoting myself from my reply to you on the android-developers Google Group, since you elected to cross-post:

  1. Pass a Cursor to your ItemizedOverlay that contains your coordinates, retrieved from your database

  2. Implement size() in your ItemizedOverlay to return getCount() from the Cursor

  3. Implement getItem() in your ItemizedOverlay to moveToPosition() on the Cursor, read out the latitude and longitude, convert to microdegrees, create a GeoPoint, and return it

  4. Use the ItemizedOverlay on your MapView



来源:https://stackoverflow.com/questions/7121924/get-geopoints-from-sqlite-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!