Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用SQLite数据库数据库在地图上填充动态标记?_Java_Android_Google Maps_Google Maps Markers - Fatal编程技术网

Java 如何使用SQLite数据库数据库在地图上填充动态标记?

Java 如何使用SQLite数据库数据库在地图上填充动态标记?,java,android,google-maps,google-maps-markers,Java,Android,Google Maps,Google Maps Markers,我将纬度和经度存储到数据库中,并希望在地图上填充这些保存位置的标记 我将数据放入数组列表,但我不知道如何在地图上填充 ArrayList<Double> get_location(){ ArrayList<Double> location = new ArrayList<>(); SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery

我将纬度和经度存储到数据库中,并希望在地图上填充这些保存位置的标记

我将数据放入数组列表,但我不知道如何在地图上填充

   ArrayList<Double> get_location(){

    ArrayList<Double> location = new ArrayList<>();
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery("select latitude,longitude from "+Table_Name_Location,null);
    if(cursor.getCount() > 0){
        while (cursor.moveToNext()) {                                  
            Double latitude = cursor.getDouble(cursor.getColumnIndex(Latitude));
            Double longitude = cursor.getDouble(cursor.getColumnIndex(Longitude));
            location.add(latitude);
            location.add(longitude);
        }
    }
    cursor.close();
    return location;
} 
}

访问的公共类\u Places扩展了碎片活动在MapreadyCallback上的实现{
数据库助手数据库助手;
ArrayList alllocation=新的ArrayList();
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u访问的位置);
databaseHelper=新的databaseHelper(此);
alllocation=get_location();
SupportMapFragment mapFragment=(SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.maps);
getMapAsync(这个);
}
@凌驾
4月1日公开作废(谷歌地图谷歌地图){
//放置多个位置的地图
if(谷歌地图!=null){
对于(int i=0;i0){
while(cursor.moveToNext()){
双纬度=cursor.getDouble(cursor.getColumnIndex(纬度));
Double longitude=cursor.getDouble(cursor.getColumnIndex(longitude));
//找到你的地址
字符串地址=cursor.getString(cursor.getColumnIndex(地址));
HashMap hash=新的HashMap();
hash.put(“纬度”,纬度);
hash.put(“经度”,经度);
hash.put(“地址”,address);
location.add(散列);
}
}
cursor.close();
返回位置;
}
}

若创建带有纬度和经度的模型类,从DB中获取lat和long,并将其设置在模型中,然后将该模型添加到列表中,该怎么办。很简单way@MD先生,您能给我推荐一些参考帖子吗?在这段代码中,您是从数据库中获取数据的?我只获取与问题相同的数据,只更改ArrayList类型,因为ArrayList不存储密钥,值。如果您愿意,那么我创建了没有数据库的自定义arraylist。非常感谢您,先生……但我还想查看保存在数据库中的地名GoogleMap.addMarker(new MarkerOptions().position(alllocation.get(i)).title(“title”))从数据库获取地址并更改“title”字符串。当你们点击标记图标时,你们可以看到你们的地址,但arrylist类型是Latlang?
public class Visited_Places extends FragmentActivity implements OnMapReadyCallback {

DatabaseHelper databaseHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_visited__places);
    databaseHelper = new DatabaseHelper(this);
    SupportMapFragment mapFragment = (SupportMapFragment)
            getSupportFragmentManager()
                    .findFragmentById(R.id.maps);

    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {


}
public class Visited_Places extends FragmentActivity implements OnMapReadyCallback {

    DatabaseHelper databaseHelper;

    ArrayList<HashMap<String, Object>> alllocation = new ArrayList<HashMap<String, Object>>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_visited__places);
        databaseHelper = new DatabaseHelper(this);
        alllocation = get_location();
        SupportMapFragment mapFragment = (SupportMapFragment)
                getSupportFragmentManager()
                        .findFragmentById(R.id.maps);

        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
//put multiple location map
        if (googleMap != null) {
            for (int i = 0; i < alllocation.size(); i++) {
                HashMap<String, Object> hash = alllocation.get(i);
                Double lat = (Double) hash.get("latitude");
                Double lang = (Double) hash.get("longitude");
                String address = hash.get("address").toString();

                if (i == 0) {
                    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lang), 14));

                }
                googleMap.addMarker(new MarkerOptions().position(new LatLng(lat, lang))
                        .title(address));


            }
        }


    }
    //getting location from database  
    ArrayList<HashMap<String, Object>> get_location(){

        ArrayList<HashMap<String, Object>> location = new ArrayList<HashMap<String, Object>>();
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery("select address,latitude,longitude from "+Table_Name_Location,null);
        if(cursor.getCount() > 0){
            while (cursor.moveToNext()) {
                Double latitude = cursor.getDouble(cursor.getColumnIndex(Latitude));
                Double longitude = cursor.getDouble(cursor.getColumnIndex(Longitude));
                //get your address
                String address = cursor.getString(cursor.getColumnIndex(Address));

                HashMap<String, Object> hash = new HashMap<String, Object>();
                hash.put("latitude", latitude);
                hash.put("longitude", longitude);
                hash.put("address", address);
                location.add(hash);
            }
        }
        cursor.close();
        return location;
    }
}