Hi I am newbie to programming and would like some assistance please.
I want to create a filter to show specific markers as per user selection (CheckBoxes).
The Filter must have Public Markers and Private Markers option (The database has a column 'RadioButton' which will either have values "public" or "Private") .
I have managed to add/show all marker stored in SQLite database to my Map but I need to arrange them in groups and allow user to select (Checkbox) which ever one they need to display.
here is my Code to add all markers:
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 : With Checkboxes
<?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>
Aucun commentaire:
Enregistrer un commentaire