获取纬度和经度从SQLite数据库在Android的MapOverlay使用 [英] Get Latitude and Longitude from SQLite database for use in Android MapOverlay

查看:153
本文介绍了获取纬度和经度从SQLite数据库在Android的MapOverlay使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我储存了一堆位置的经度和纬度在SQLite数据库,我将如何检索这些值,并把它们每一个OverlayItem类在谷歌的地图code使用?

If I store the Latitude and Longitude of a bunch of locations in a SQLite Database, how would I retrieve these values and place them each in an OverlayItem class for use in Google's Map code?

数据库名称:数据库

表名称:地点

字段中的地点表:

  • ID
  • 标题
  • 说明
  • 纬度
  • 经度
  • id
  • title
  • description
  • latitude
  • longitude

如何获得每个位置的经纬度数据,并将其添加到一个ArrayList itemOverlay?

How do I get the latitude and longitude data of each location and add it to an ArrayList itemOverlay?

你有什么想法或一个例子吗?谢谢你这么多。

Do you have any ideas or an example? Thanks you so much

推荐答案

您会想要做这样的查询:

You would want to do a query like this:

SELECT title, description, latitude, longitude
FROM place

可以在Android的就像这样:

Which can be done in Android like this:

    /* 
       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());

您需要通过1E6,因为Android使用重的纬度/经度值presentation整数相乘的值。如果您已经填充数据库的时候照顾了这一点,跳过乘法,并使用 locationCursor.getInt(...)

You need to multiply the values by 1E6 because Android uses an integer representation of the lat/long values. If you already took care of this when populating the database, skip the multiplication and use locationCursor.getInt(...).

这篇关于获取纬度和经度从SQLite数据库在Android的MapOverlay使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆