【问题标题】:how to show locations on google map activity stored in sql database如何在存储在 sql 数据库中的谷歌地图活动上显示位置
【发布时间】:2016-07-28 03:26:15
【问题描述】:

如何在存储在从位置数组列表存储的 sql 数据库中的谷歌地图活动上显示位置。我正在使用地理编码器类来获取位置的经度和纬度,请帮助我执行相同的过程

【问题讨论】:

    标签: android sql google-maps


    【解决方案1】:

    我假设你有一个对象类 Location,它包含标题、纬度、经度。在您的数据库中,它还有 3 列标题、纬度和经度。

    现在你的数据库类扩展了 SQLiteOpenHelper,你应该有:

    private SQLiteDatabase database;
    

    然后使用下面的方法将所有位置放入一个数组列表中,您可以使用该返回列表做任何您想做的事情。

    public ArrayList<Location> getLocationList() {
    
            ArrayList<Location> locationList = new ArrayList<>();
            String query = "SELECT * FROM Your_Table_Name";
            Cursor cursor = database.rawQuery(query, null);
    
            int ColumeLatitude = cursor.getColumnIndex("Latitude");
            int ColumeLongitude = cursor.getColumnIndex("Longitude");
            int ColumeTitle = cursor.getColumnIndex("Title");
    
            while (cursor.moveToNext()) {            
                String title = cursor.getString(ColumeTitle);
                String latitude = cursor.getString(ColumeLatitude);
                String longitude = cursor.getString(ColumeLongitude);
    
                Location location = new Location(title, latitude, longitude);
                locationList.add(location);
            }
    
            cursor.close();
            return locationList;
        }
    

    希望对你有帮助!

    【讨论】:

    • 对不起朋友你不理解我的问题我有存储在我的数组列表中的位置地址然后我将它存储在数据库中然后如何显示我现在希望存储的所有位置 int 数据库你会理解我的问题,如果有任何与我的问题相关的答案,请回复
    • 感谢您的尝试,但如果我尝试使用 geocder 类,因为此类不需要任何位置的经度和纬度,它只需要位置地址,所以如果您有任何与此相关的想法,请告诉我
    • 我没有使用 Geocoder 类,但我认为这个链接可能对你有帮助:stackoverflow.com/questions/15711499/…
    猜你喜欢
    • 2019-04-18
    • 2012-12-17
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多