If you have a use case that requires searching and selecting a specific location on map , Here is a nice independent module that you can simply import into your project to handle this scenario with some customizations
- Rich autoComplete and search for any location with the ability to filter results depending on country.
- Get parsed string address for any location on map with a specified language.
- Restrict specific supported areas for user to only pick from .
- Listen for GPS configuration changes and ask user to enable GPS once it is disabled.
- Minimum SDK version 21
- Androidx
- Google Places Api key
- your project manifest file contains internet and location permissions
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- add meta_data for google api key in application tag within manifest file
<application
--
--
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/places_api_key" />
</application>
Make sure that you have original google places api key not only google maps key as autocomplete won't work without Places key.
- add this code to the the project level build.gradle file
allprojects {
repositories {
--
--
maven { url "https://jitpack.io" }
}
}
- Clone or download simplePlacePicker and save it at a path that you know.
- In your android project, Go to File > New > Import Module..
- Enter the path of simpleplacepicker module and click finish.
- After android studio finishes syncing, go to File > Project Structure and select Dependencies.
- Now you should see that you have two modules , your app module and simpleplacepicker module
- Select app module and in Declared dependencies section click the plus icon and choose Module Dependency
- Choose simpleplacepicker and click Ok.
just create intent and add extras to get some customization
Intent intent = new Intent(this, MapActivity.class);
Bundle bundle = new Bundle();
bundle.putString(SimplePlacePicker.API_KEY,apiKey);
bundle.putString(SimplePlacePicker.COUNTRY,country);
bundle.putString(SimplePlacePicker.LANGUAGE,language);
bundle.putStringArray(SimplePlacePicker.SUPPORTED_AREAS,supportedAreas);
intent.putExtras(bundle);
startActivityForResult(intent, SimplePlacePicker.SELECT_LOCATION_REQUEST_CODE);
Example project : TestPlacePicker
- MaterialSearchBar https://github.com/mancj/MaterialSearchBar
- android-ripple-background https://github.com/skyfishjy/android-ripple-background