/ AutoComplete

A simple library that can connect your autocomplete edittext to Google places api

A simple library that can connect your autocomplete edittext to Google places api

Google Places AutoComplete EditText

A simple library that can connect your autocomplete edittext to Google's places api.

How to integrate into your app?

Integrating the project is simple a refined all you need to do is follow the below steps

Step 1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:

allprojects {
  repositories {
    ...
    maven { url "https://jitpack.io" }
  }
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.mukeshsolanki:Google-Places-AutoComplete-EditText:<latest-version>'
}

How to use the library?

Okay seems like you integrated the library in your project but how do you use it? Well its really easy just add the following to your xml design

.....
 <AutoCompleteTextView
    android:id="@+id/autoCompleteEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
.....

To connect the AutoCompleteTextView to the places api create a PlaceApi object and attach it to the AutoCompleteTextView like-wise

 val placesApi = PlaceAPI()
 placesApi.initialize("YOUR_API_KEY",context)
 autoCompleteEditText.setAdapter(PlacesAutoCompleteAdapter(this, placesApi))

That's pretty much it and your all wrapped up. You have successfully connected the Places Api to the AutoCompleteTextView.

Getting details of place

To get the selected address simply set an ItemClickListener

autoCompleteEditText.onItemClickListener =
      AdapterView.OnItemClickListener { parent, _, position, _ ->
        val place = parent.getItemAtPosition(position) as Place
        autoCompleteEditText.setText(place.description)
      }

To get the details of the place selected you can set a listener to get the details

placesApi.fetchPlaceDetails("placeId", object : OnPlacesDetailsListener {
      override fun onError(errorMessage: String) {
        Toast.makeText([email protected], errorMessage, Toast.LENGTH_SHORT).show()
      }

      override fun onPlaceDetailsFetched(placeDetails: PlaceDetails) {
        //TODO do anything with placeDetails object
      }
    })

GitHub