Android Places Search View

A small library that integrating your autocomplete Edittext to the Google Places API.

DEMO

Installation

To get a Git project into your build:

Step 1. Add the JitPack repository to your build file

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

Step 2. Add the dependency

  dependencies {
	   implementation 'com.github.fsfaysalcse:AndroidPlaceSearchVew:1.1'
	}

Usage

<AutoCompleteTextView 
    android:id="@+id/autoCompleteEditText" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:background="@drawable/bg_auto_compleate"
    android:hint="@string/type_in_your_location" 
    android:padding="8dp" />

class MainActivity : AppCompatActivity() {

    lateinit var binding: ActivityMainBinding

    val placesApi = PlacesView.Builder()
        .apiKey(GOOGLE_MAP_API_KEY)
        .build(this@MainActivity)


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.autoCompleteEditText.setAdapter(PlacesAutoCompleteAdapter(this, placesApi))
    }
}

For handle item click event

    autoCompleteEditText.onItemClickListener = AdapterView.OnItemClickListener { parent, _, position, _ ->
    val place = parent.getItemAtPosition(position) as Places

}

Getting details of places

   placesApi.getPlaceDetails(placeId, object : OnPlaceDetailsListener {
    override fun onError(errorMessage: String) {

    }

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

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would
like to change.

Please make sure to update the tests as appropriate.

GitHub

View Github