Mindinventory / vanilla-place-picker

Simple(vanilla) yet 'Do it all' place picker for your place picking needs in Android
https://www.mindinventory.com/android-application-development.php
MIT License
120 stars 34 forks source link
android autocomplete easy-to-use google-map google-place-autocomplete google-places kotlin kotlin-android location location-picker picker placepicker places vanilla

Vanilla Place Picker

Vanilla Place Picker provides a UI that displays an interactive map to get the place details and Autocomplete functionality, which displays place predictions based on user search input.

Developers often come across a requirement of adding precise location. So, a place picker which is easy to implement, less time consuming, and simple enough for users to use it is always in demand and here we have a Vanilla Place Picker which developer can add it in quick simple steps.

Preview

image image

Key features

Usage

Dependencies

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

Implementation

      <application ... >
        ...

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="${googleMapsApiKey}" />

      </application>

startActivityForResult is deprecated so better to use registerForActivityResult

 var placePickerResultLauncher =
   registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
       if (result.resultCode == Activity.RESULT_OK && result.data != null) {
           val vanillaAddress = VanillaPlacePicker.getPlaceResult(result.data)
       }
   }

Launch caller with Intent

 val intent = VanillaPlacePicker.Builder(this)
    .with(PickerType.MAP_WITH_AUTO_COMPLETE) // Select Picker type to enable autocompelte, map or both
    .withLocation(23.057582, 72.534458)
    .setPickerLanguage(PickerLanguage.HINDI) // Apply language to picker
    .setLocationRestriction(LatLng(23.0558088,72.5325067), LatLng(23.0587592,72.5357321)) // Restrict location bounds in map and autocomplete
    .setCountry("IN") // Only for Autocomplete
    .enableShowMapAfterSearchResult(true) // To show the map after selecting the place from place picker only for PickerType.MAP_WITH_AUTO_C
    /*
     * Configuration for Map UI
     */
    .setMapType(MapType.SATELLITE) // Choose map type (Only applicable for map screen) 
    .setMapStyle(R.raw.style_json) // Containing the JSON style declaration for night-mode styling
    .setMapPinDrawable(android.R.drawable.ic_menu_mylocation) // To give custom pin image for map marker
    .build()

 placePickerResultLauncher.launch(intent)


## Requirements

* minSdkVersion >= 21
* Androidx

# LICENSE!

Vanilla Place Picker is [MIT-licensed](/LICENSE).

# Let us know!
We’d be really happy if you send us links to your projects where you use our component. Just send an email to sales@mindinventory.com And do let us know if you have any questions or suggestion regarding our work.