Android Places Autocomplete Example

Location based application are becoming very common now a days. If we want to implement an application like Uber or Ola which provide cab services user might be needed to input their pick and drop locations and suppose if it is a buy and sell application also user need to input their location. More accurate input will make the business easier.

So it is developers responsibility to provide an interface which user can easily input accurate location.For getting the accurate input location it is always good to have search input which will show list of location suggestion based on users input.

In android , places autocomplete search input can be easily implemented using google API.Here we will learn how to implement a places autocomplete in android. For using Google Places API you need to configure an API key in Google developers console of your account. We will start with configuring API key at console.

Steps for configuring API key

  1. Go to link
  2. Scroll down to section “Get an API key from the Google API Console”.


3. Click on “Get A Key button”, The following popup will be displayed.


4.  Here you can create a new project or select an existing project and finally click on “Enable Api” Button.

You must get the following screen


5. Note down the the Api key mentioned there.

Next step is to implement Android project


  1. Create a new project in android studio
  2. Add the location dependency to your apps gradle file.
  3. Place the API key in AndroidManifest.xml
  4. Autocomplete widget to the layout file.
  5. Implement the code the be executed when the user clicks on suggested item.
  6. How to display places filtered by countries or cities

Create New project in android studio

Refer Android beginners app development guide if you are beginner or if you don’t know how to create project in android studio.

Add the location dependency to your apps gradle file

Add the following dependency to your buid.gradile

compile ''
compile ''

Place the API key in AndroidManifest.xml

Add the following tag to your  AndroidManifest.xml under application tag.

<meta-data android:name="" android:value="Your api key"/>

Autocomplete widget to the layout file

Following is a fragment widget which will display the autocomplete fragment in your application .All you need to do is to just copy the following code and add to your activity’s layout file.


 Now if you run the code you can see a search box .When you type on search box it will start listing places.

Implement the code the be executed when the user clicks on suggested item

Once the widget is added to your layout you can see the search box which will show location suggestion based on the keyword user is typing . But for picking the location information of the item which the user is clicked,we need to implement some code on the activity’s java file. It is nothing complicated ,we just need to add the following place selected listener which will give all places information when one place is selected

PlaceAutocompleteFragment places= (PlaceAutocompleteFragment)
places.setOnPlaceSelectedListener(new PlaceSelectionListener() {
    public void onPlaceSelected(Place place) {

    public void onError(Status status) {
 Run your project ,You will get the following output


How to display places filtered by countries.

Now the above code is giving output will places all over the world . Now suppose if you want to display only places in a particular country you need to have a country filter for your autocomplete fragment. Here in the following code i am implementing the filter to list only the places in country US.

AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()

And another feature of places auto complete fragment is you can filter the places which should be listed in suggestion, Like suppose if you want to show just city name instead of entire address, you can add the filter like this:

AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()


if you run this code ,it will show only cities. Here is the list of filters you can give inside a AutocompleteFilter


Refer Android autocomplete textview example if you want to implement normal auto complete textview.

About the author

Hi guys, i am the author of codesfor. I am a B.Tech graduate currently working as an App developer. Apart from job i am a blogger and a freelancer.


  1. Ganesh Kumrawat July 13, 2019 Reply
    • Ramees FazalAuthor July 24, 2019 Reply

Add a Comment

Your email address will not be published. Required fields are marked *