Как отфильтровать маркеры на Android Map из Sqlite - PullRequest
0 голосов
/ 06 сентября 2018

Я хочу создать фильтр для отображения определенных маркеров в соответствии с выбором пользователя (флажки).

Фильтр должен иметь параметры «Открытые маркеры» и «Частные маркеры», поскольку в базе данных есть столбец «RadioButton», который будет иметь значения «public» или «Private».

Мне удалось добавить / показать все маркеры, хранящиеся в базе данных SQLite, на моей карте, но мне нужно упорядочить их по группам и позволить пользователю выбрать (флажок), какой из них ему нужно отобразить.

вот мой код для добавления всех маркеров:

public void onMapReady(GoogleMap googleMap) {

mGoogleMap = googleMap;

Database_Helper dbHelper = new Database_Helper(Maps.this);
   try {
      dbHelper.getDatabaseName();
    } catch (Exception e) {
    Toast.makeText(Maps.this, "Database Does not Exists",       Toast.LENGTH_SHORT).show();
    }
  final SQLiteDatabase db = dbHelper.getReadableDatabase();

  Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME, null);
        LatLngBounds.Builder mapBuilder = new LatLngBounds.Builder();
  boolean addedMarker = false;

  if (cursor != null) {
      while (cursor.moveToNext()) {

        int lat = cursor.getColumnIndexOrThrow(COL3);
        int lng = cursor.getColumnIndexOrThrow(COL4);
        int title = cursor.getColumnIndexOrThrow(COL5);
        int radiob = cursor.getColumnIndexOrThrow(COL13);

        String title = cursor.getString(title);
        double latitude = cursor.getDouble(lat);
        double longitude = cursor.getDouble(lng);
        String radio = cursor.getString(radiob);

        LatLng location = new LatLng(latitude, longitude);
        MarkerOptions options = new MarkerOptions()
                .title(event)
                .snippet(date)
                .position(location)
                .anchor(0.5F, 1.0F)
                .icon(BitmapDescriptorFactory.defaultMarker        

       (BitmapDescriptorFactory.HUE_AZURE))
                .draggable(false);

        final Marker marker = mGoogleMap.addMarker(options);
        mapBuilder.include(marker.getPosition());

        addedMarker = true;`

My Xml Layout: с флажками

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
    android:layout_height="match_parent">

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="440dp"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    tools:context="com.sbkgroup.a411.e_connect.Maps" />

<LinearLayout
    android:layout_alignBottom="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical">

    <CheckBox
        android:id="@+id/public1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toEndOf="@+id/public1"
        android:text="Public" />

    <CheckBox
        android:id="@+id/private1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Private" />
   </LinearLayout>
 </RelativeLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...