How can I filter my location using AutoCompleteTextView in Google Map Android?

  • Replies:7
  • OpenNot stickiedUnanswered
  • Forum posts: 4

Sep 13, 2015, 5:23:57 AM via Website


I am using the MapActivity with AutoCompleteTextView, Button, and Map Fragment. Mapactivity.xml file attachedimage
I want to filter my location using the AutoCompleteTextView.My sqlite database consist as follows:

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

If I select "Excellent" in my AutoCompleteTextView and press Show Map Button. It Should show the location of my "Excellent" only with Marker i.e ID . Example I select "Good", Show the location for ID 2,8,& 9.Please Help me How can I write a code in Android Studio.

  • Forum posts: 211

Sep 14, 2015, 7:56:07 AM via Website

Ok so locations are in your local database.

For Studio first introduce the google play services in your project gradle file. (rather like in eclipse import the play services as a lib project). Also activate the google map services from google console. mention play services meta data in you project manifest.xml.

on click of show button fetch the lat ,long from your db and pass to location.

  • Forum posts: 4

Sep 14, 2015, 9:36:31 AM via Website


I already have my G play service in gradle. My question is How can I filter it. Right now I am getting all the 10 location in Map. I want them to filter like If I type "Good", It should show only Good location. Pl see my db table above.

  • Forum posts: 211

Sep 14, 2015, 10:24:58 AM via Website

indeed i have seen your table. when you are typing like good only get the coordinate of that. i think your query is fetching all the location and send to the map. can you share that piece of code so i will have some idea to help you.

  • Forum posts: 4

Sep 14, 2015, 10:48:03 AM via Website

Ashish here is my code: I have used "Ifelse condition" If my textview is empty display all location else use to filter the location. Pl help me to do coding for this

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


protected void onCreate(Bundle savedInstanceState) {

    inputSearch = (AutoCompleteTextView) findViewById(;
    ArrayAdapter adapter1 = new ArrayAdapter(this, android.R.layout.select_dialog_item, conditions);
    btMap = (Button) findViewById(;

    //At layout actitvity-maps used onClick = onsearch to used the MapButton as listern

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

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

            //When My autocompletetextview is empty and press button show all the location
            if(search.equals("")) {
                double latitude = 0;
                double longitude = 0;
                // SQLite database handler
                db = new TreeData(getApplicationContext());

                Cursor locationCursor = db.getLocations();


                do {
                    latitude = locationCursor.getDouble(locationCursor
                    longitude = locationCursor.getDouble(locationCursor

                    LatLng location = new LatLng(latitude, longitude);

                    mMap.addMarker(new MarkerOptions().position(location).title("Marker"));

                } while (locationCursor.moveToNext());

            //When My autocompletetextview is "Condition" and press button show only selected location
                Toast.makeText(getApplicationContext(), "Enter the search", Toast.LENGTH_LONG).show();


  • Forum posts: 211

Sep 14, 2015, 11:19:11 AM via Website

//When My autocompletetextview is "Condition" and press button show only selected location
Toast.makeText(getApplicationContext(), "Enter the search", Toast.LENGTH_LONG).show();

if your auto complete text has condition that this else will execute. write your code here for input location filter i.e. if good than only coordinates for good will fetch out from db.

  • Forum posts: 4

Sep 14, 2015, 11:22:31 AM via Website

Ashish, How to write a code to do that?

  • Forum posts: 211

Sep 14, 2015, 12:03:19 PM via Website

what you can do like i am assuming that your columns are id,condition, latitude,longitude.

inside your else condition you can pass the query to your database class,

select latitude,longitude from 'table name' where condition = 'enter condition'.

the cursor will return only input condition latitude and longitude if exist. also catch the null pointer exception in case no data found.

Recommended articles