简体   繁体   English

从SQlite DB获取Geopoints

[英]Get Geopoints from SQlite DB

I created an SQlite database to store on it all latitudes and longitudes to display them in map. 我创建了一个SQlite数据库来存储所有经度和纬度以在地图中显示它们。 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? 如何浏览所有数据库并自动添加所有Geopoint? 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();

Quoting myself from my reply to you on the android-developers Google Group, since you elected to cross-post : 自从您选择交叉发布以来,我就拒绝了我在android-developers Google网上论坛上给您的回复:

  1. Pass a Cursor to your ItemizedOverlay that contains your coordinates, retrieved from your database Cursor传递到包含从数据库中检索到的坐标的ItemizedOverlay

  2. Implement size() in your ItemizedOverlay to return getCount() from the Cursor ItemizedOverlay实现size()以从Cursor返回getCount()

  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 ItemizedOverlay实现getItem()以在Cursor上移动moveToPosition() ,读出纬度和经度,转换为微度,创建一个GeoPoint ,然后将其返回

  4. Use the ItemizedOverlay on your MapView MapView上使用ItemizedOverlay

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM