- Google Place Picker Activity
- Google Map
- Google Location
- Google Place Picker (AutoComplete text View)
Use Gradle: Step 1. 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.devinda-ewind:googleapis:version'
}
Or Maven:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.devinda-ewind</groupId>
<artifactId>googleapis</artifactId>
<version>Tag</version>
</dependency>
initialize places api in application
class App : Application() {
override fun onCreate() {
super.onCreate()
Places.initialize(applicationContext, getString(R.string.google_map_key))
}
}
Start place picker activity
override fun onClick(v: View?) {
when (v?.id) {
R.id.et_address -> {
startPlacePicker()
}
}
}
Get result from getLocationFromResult(requestCode, resultCode, data)
override fun onActivityResult(
requestCode: Int,
resultCode: Int,
data: Intent?
) {
super.onActivityResult(requestCode, resultCode, data)
context?.getLocationFromResult(requestCode, resultCode, data)
?.let {
et_address.setText(it.address)
latitude = it.latitude
longtude = it.longtude
}
}
Initialize googlePlackPickerManager
val googlePlacePickerManager = GooglePlacePickerManager(context)
internal fun initPlaceSearch(completeTextView: AutoCompleteTextView) {
googlePlacePickerManager.initialPlace(
completeTextView,
object : GooglePlacePickerCallback() {
override fun googlePlacePickerCallback(place: Place) {
//selected google place
}
})
}
Get Address from LatLng
val googlePlacePickerManager = GooglePlacePickerManager(context)
fun...{
googlePlacePickerManager.initialGeoCode(latlng)
}
internal fun initPlaceSearch(completeTextView: AutoCompleteTextView) {
googlePlacePickerManager.initialPlace(
completeTextView,
object : GooglePlacePickerCallback() {
override fun googleAddressCallback(googleLocation: GoogleLocation) {
//
}
})
}