samedi 19 septembre 2015

Android Google Map Markers colour changinig/visualisation using sqlite database

How to change the colour of Marker based on selected values?

  1. When I type "Excellent" from sqlite db. It should shows only the "Excellent" location markers in "RED" Colour.

  2. When I type "Good" from sqlite db. It should shows only the "Good" location markers in "Blue" Colour.

  3. When I type "Fair" from sqlite db. It should shows only the "Fair" location markers in "White" Colour.

Pl look my db, and suggest How to write code below my code:?

My SQLITE database columns are:

    //Table Columns names
private static final String KEY_TID = "id";
public static final String KEY_TreeID = "treeid";
public static final String KEY_TCONDITION = "condition";
public static final String KEY_TLATITUDE = "latitude";
public static final String KEY_TLONGITUDE = "longitude";

My sqlite Database:

ID  Condition   Latitude    Longitude
1   Excellent   12.897485   15.425974
2   Good        12.897485   15.425974
3   Excellent   12.897485   15.425974
4   Excellent   12.897485   15.425974
5   Excellent   12.897485   15.425974
6   Excellent   12.897485   15.425974
7   Good        12.897485   15.425974
8   Fair        12.897485   15.425974
9   Fair        12.897485   15.425974
10  Fair        12.897485   15.425974


  private AutoCompleteTextView inputSearch;
String[] conditions = {"Excellent",
        "Good",
        "Fair",

};

My MapActivity:

 btMap.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String search = inputSearch.getText().toString();

            if(search.equals("")) {
                double latitude = 0;
                double longitude = 0;
                String mark;

                // SQLite database handler
                db = new TreeData(getApplicationContext());



                Cursor locationCursor = db.getLocations();

                locationCursor.moveToFirst();

                do {
                    latitude = locationCursor.getDouble(locationCursor
                            .getColumnIndex(SQLiteHandler.KEY_TLATITUDE));
                    longitude = locationCursor.getDouble(locationCursor
                            .getColumnIndex(SQLiteHandler.KEY_TLONGITUDE));

                    mark = locationCursor.getString(locationCursor
                            .getColumnIndex(SQLiteHandler.KEY_TreeID));

                    LatLng location = new LatLng(latitude, longitude);

                    mMap.addMarker(new MarkerOptions().position(location).title(mark));


                } while (locationCursor.moveToNext());

            }


            if(search.length()>0){

                //float zoom = 0;
                mMap.clear();

                // SQLite database handler
                db = new TreeData(getApplicationContext());


                Cursor c = db.getSelectedLocations(search);


                c.moveToFirst();

                do {

                   double latitude1 = c.getDouble(c
                            .getColumnIndex(SQLiteHandler.KEY_TLATITUDE));
                    double longitude1 = c.getDouble(c
                            .getColumnIndex(SQLiteHandler.KEY_TLONGITUDE));

                    String marker = c.getString(c
                            .getColumnIndex(SQLiteHandler.KEY_TreeID));

                    LatLng location = new LatLng(latitude1, longitude1);

                    mMap.addMarker(new MarkerOptions().position(location).title(marker));

                    // Moving CameraPosition to last clicked position
                    mMap.moveCamera(CameraUpdateFactory.newLatLng(location));

                    // Setting the zoom level in the map on last position is clicked
                     mMap.animateCamera(CameraUpdateFactory.newLatLng(location));


                } while (c.moveToNext());
                Toast.makeText(getApplicationContext(), "All is Well", Toast.LENGTH_LONG).show();
        }
            else{

                Toast.makeText(getApplicationContext(), "Invalid", Toast.LENGTH_LONG).show();
            }
    }
});}

Aucun commentaire:

Enregistrer un commentaire