Apr*_*ith 3 database sqlite android android-maps mapactivity
如果我在SQLite数据库中存储一堆位置的纬度和经度,我如何检索这些值并将它们放在OverlayItem类中以便在Google的Map代码中使用?
数据库名称: database
表名: place
place表中的字段:
id titledescriptionlatitudelongitude如何获取每个位置的纬度和经度数据并将其添加到ArrayList itemOverlay?
你有什么想法或例子吗?非常感谢
您可能想要执行以下查询:
SELECT title, description, latitude, longitude
FROM place
Run Code Online (Sandbox Code Playgroud)
这可以在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());
Run Code Online (Sandbox Code Playgroud)
您需要将值乘以1E6,因为Android使用纬度/经度值的整数表示.如果在填充数据库时已经处理了这个问题,请跳过乘法并使用locationCursor.getInt(...).