2

以前の質問に従っていました (ここにあります: Get Latitude and Longitude from SQLite database for use in Android MapOverlay )

私はそこにあるコードを理解しており、私のデータベースには 4 つの列があるという点で同様のレイアウトがあります。ID、名前、緯度、経度。そのテーブルからすべてを選択し、緯度経度をオーバーレイのポイントとして配置するという点で、そこで言われていることをしたいとさえ思っています。私の問題は、答えにはいくつかの前提条件が必要であるため、その作業を行うために必要なものについて誰かが助けてくれるかどうか疑問に思っていました.

事前に感謝します。これが私が編集したコードの現在の状態です。

ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
        Cursor locationCursor = databaseObject.query("locations", new String[] {"image_id", "name", "lat", "lng" }, null, null, null, null);

        locationCursor.moveToFirst();
        do {
            String image_id = locationCursor.getString(locationCursor
                    .getColumnIndex("image_id"));
            String name = locationCursor.getString(locationCursor
                    .getColumnIndex("name"));
            int latitude = (int) (locationCursor.getDouble(locationCursor
                    .getColumnIndex("lat")) * 1E6);
            int longitude = (int) (locationCursor.getDouble(locationCursor
                    .getColumnIndex("lng")) * 1E6);
            items.add(new OverlayItem(new GeoPoint(latitude, longitude), image_id, name));
        } while (locationCursor.moveToNext());

より具体的には、databaseObject.query でエラーが発生します。これは、これより前にパーツがないためだと想定しています。

編集。

さらに明確にするために、phpmyadmin のテーブルから緯度と経度の値を取得し、Google マップ オーバーレイの Android アプリケーションに表示することを目的としています。上記のコードは、私が見つけたが、コードの前にいくつかの部分が必要だったために機能させることができなかった例の表示です

4

2 に答える 2

1

クエリがレコードを返さない場合、カーソルは空になり、do whileステートメントはとにかく実行され、最終的にエラーがスローされます。これを試して

編集::

        SQLiteDatabase databaseObject = null; 
        databaseObject = this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
        ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
        Cursor locationCursor = databaseObject.query("locations", new String[] {"image_id", "name", "lat", "lng" }, null, null, null, null);


         while (locationCursor.moveToNext()){
            String image_id = locationCursor.getString(locationCursor
                    .getColumnIndex("image_id"));
            String name = locationCursor.getString(locationCursor
                    .getColumnIndex("name"));
            int latitude = (int) (locationCursor.getDouble(locationCursor
                    .getColumnIndex("lat")) * 1E6);
            int longitude = (int) (locationCursor.getDouble(locationCursor
                    .getColumnIndex("lng")) * 1E6);
            items.add(new OverlayItem(new GeoPoint(latitude, longitude), image_id, name));
        }
于 2012-04-25T00:59:28.353 に答える
0

おそらく、データベース サーバー側で php にコードを記述し、データベースを取得してから、結果を JSON として渡す必要があります。このリンクこれを参照してください。

于 2012-04-25T02:17:14.510 に答える