Add multiple geopoints and markers automatically in Google Maps

后端 未结 2 1542
旧时难觅i
旧时难觅i 2021-02-06 19:50

Is it possible to make the addition of a geopoint in a map more \"automatic\"? I mean, if we have many points to add in the map (more than 100), we don\'t have to add them one b

相关标签:
2条回答
  • 2021-02-06 20:13

    You could store them in a SQLite databse, and pull them as needed

    0 讨论(0)
  • 2021-02-06 20:29

    You'll want to store them in either a SQLite database or some other form of data storage, and then you can pull them in and place them on the map with an ItemizedOverlay, see Google Map View (a tutorial).

    Create your array from a database cursor

    Cursor cursor =  mDbHelper.getItems();
    cursor.moveToFirst();
    
    List<CatchItem> catchList = new ArrayList<CatchItem>();
    
    if (cursor != null && cursor.getCount() > 0) {
        for (int i = 0; i < cursor.getCount(); i++) {
            CatchItem item = new CatchItem();
    
            item.Latitude = cursor.getDouble(cursor.getColumnIndex("latitude"));
            item.Longitude = cursor.getDouble(cursor.getColumnIndex("longitude"));
    
            catchList.add(item);
            cursor.moveToNext();
        }
    }
    

    ItemizedOverlay

    List<Overlay> overlays = mMaps.getOverlays();
    overlays.clear();
    CatchesItemizedOverlay catchOverlays = new CatchesItemizedOverlay(getResources().getDrawable(R.drawable.map_markeroverlay_blue72), this);
    
    for (int i = 0; i < catchList.size(); i++) {
        double lat = catchList.get(i).Latitude;
        double lng = catchList.get(i).Longitude;
    
        GeoPoint geopoint = new GeoPoint((int)(lat*1E6), (int)(lng*1E6));
        catchOverlays.addOverlay(new CatchOverlayItem(this, geopoint, catchList.get(i)));
    }
    
    overlays.add(catchOverlays);
    

    CatchesItemizedOverlay is my own extended ItemizedOverlay (I needed custom functionality). The catchList object is just a custom object that has latitude and longitude.

    Hopefully this works for you.

    0 讨论(0)
提交回复
热议问题