3

多数の場所の緯度と経度をSQLiteデータベースに保存する場合、これらの値を取得して、Googleのマップコードで使用するためにそれぞれをOverlayItemクラスに配置するにはどうすればよいですか?

データベース名:database

テーブル名:place

表のフィールドplace

  • id
  • title
  • description
  • latitude
  • longitude

各場所の緯度と経度のデータを取得して、それをArrayList itemOverlayに追加するにはどうすればよいですか?

アイデアや例はありますか?ありがとうございます

4

1 に答える 1

6

次のようなクエリを実行します。

SELECT title, description, latitude, longitude
FROM place

これは、次のように Android で実行できます。

    /* 
       databaseObject = YourDbHelper#getReadableDatabase();
    */
    ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
    Cursor locationCursor = databaseObject.query("place", new String[]{
            "title", "description", "latitude", "longitude"}, null, null,
            null, null, null);

    locationCursor.moveToFirst();

    do {
        String title = locationCursor.String(locationCursor
                .getColumnIndex("title"));
        String description = locationCursor.String(locationCursor
                .getColumnIndex("description"));
        int latitude = (int) (locationCursor.getDouble(locationCursor
                .getColumnIndex("latitude")) * 1E6);
        int longitude = (int) (locationCursor.getDouble(locationCursor
                .getColumnIndex("longitude")) * 1E6);

        items.add(new OverlayItem(new GeoPoint(latitude, longitude), title,
                description));
    } while (locationCursor.moveToNext());

Android は緯度/経度値の整数表現を使用するため、値に 1E6 を掛ける必要があります。データベースに入力するときにすでにこれを処理している場合は、乗算をスキップして を使用してlocationCursor.getInt(...)ください。

于 2011-09-02T18:08:21.760 に答える