Giter Site home page Giter Site logo

mindinventory / vanilla-place-picker Goto Github PK

View Code? Open in Web Editor NEW
119.0 15.0 34.0 3.74 MB

Simple(vanilla) yet 'Do it all' place picker for your place picking needs in Android

Home Page: https://www.mindinventory.com/android-application-development.php

License: MIT License

Kotlin 98.12% Java 1.88%
android kotlin kotlin-android placepicker picker vanilla autocomplete easy-to-use google-map google-place-autocomplete

vanilla-place-picker's Introduction

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

  • Android 13 support
  • Simple implementation for place picker either using Autocomplete, Map or both
  • Set your own custom map styles
  • Customise map pin icon
  • Set default location position
  • Use it without location permission
  • Choose to show only open businesses or all
  • Highly customise attributes
  • Multi languages support
  • RTL layout support

Usage

Dependencies

  • Step 1. Add the JitPack repository in your project build.gradle:
allprojects {
	    repositories {
		    ...
		    maven { url 'https://jitpack.io' }
	    }
    }

or If Android studio version is Arctic Fox or higher then add it in your settings.gradle

dependencyResolutionManagement {
  		repositories {
       		...
       		maven { url 'https://jitpack.io' }
   		}
   }
  • Step 2. Add the dependency in your app module build.gradle file
        dependencies {
            ...
            implementation 'com.github.Mindinventory:VanillaPlacePicker:X.X.X'
        }

Implementation

  • Step 1. Add Google MAP API KEY in your local.properties file with the same variable name as defined below (google.maps_api_key)
     google.maps_api_key=PLACE YOUR API KEY HERE
  • Step 2. To get Google MAP Api key from local.properties file, write below defined code in your app module build.gradle file
       android {
  ...
  defaultConfig {
  ...
  #Access Google MAP Api Key from local.properties file 
  def properties = new Properties()
  file("../local.properties").withInputStream { properties.load(it)
  #Share the key with your `AndroidManifest.xml`
  manifestPlaceholders = [ googleMapsApiKey:"${properties.getProperty('google.maps_api_key')}"]
  }
  • Step 3. Add below defined meta-data code to your AndroidManifest.xml:
      <application ... >
        ...
        
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="${googleMapsApiKey}" />
        
      </application>
  • Step 4. Add VanillaPlacePicker Builder in to your activity class:
#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.

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 [email protected] And do let us know if you have any questions or suggestion regarding our work.

vanilla-place-picker's People

Contributors

akashmi avatar chiragmi avatar dhruvmi avatar ericytsang avatar g2dgaming avatar gnzlt avatar jaldeepasodariya avatar kushangi99 avatar mahavir-mi avatar malikmotani avatar nkgohil007 avatar sanjay-mi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vanilla-place-picker's Issues

white text on white background for Theme.AppCompat (dark themes?)

white text on white background for Theme.AppCompat (dark themes?):

  • in the and autocomplete UI, the full addresses of search results have very little contrast, making it hard to see.

    • Screen Shot 2019-07-15 at 9 14 30 AM
  • in the map UI, the address in the search bar at the top is also hard to see.

    • Screen Shot 2019-07-15 at 9 14 17 AM

i have tried to work around the issue (but to no avail) by:

  • calling startActivityForResult from an activity with a theme of Theme.AppCompat.Light
  • setting the theme of the AndroidManifest's <application> to Theme.AppCompat.Light, and overriding the rest of my themes to be Theme.AppCompat

IncompatibleClassChangeError

java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.location.SettingsClient, but class was expected (declaration of 'com.google.android.gms.location.SettingsClient' appears in base.apk)

Crash when using with java

Important part:

java.lang.RuntimeException: Unable to start activity 
Caused by: android.view.InflateException: Binary XML file line #31: Binary XML file line #43: Error inflating class TextView
     Caused by: android.view.InflateException: Binary XML file line #43: Error inflating class TextView
     Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
        at android.content.res.TypedArray.getColorStateList(TypedArray.java:546)
        at android.widget.TextView.readTextAppearance(TextView.java:3873)
2019-05-29 13:21:53.067 29436-29436/com.levionsoftware.photos E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.levionsoftware.photos, PID: 29436
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.levionsoftware.photos/com.vanillaplacepicker.presentation.map.VanillaMapActivity}: android.view.InflateException: Binary XML file line #31: Binary XML file line #43: Error inflating class TextView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3086)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3229)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:6981)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
     Caused by: android.view.InflateException: Binary XML file line #31: Binary XML file line #43: Error inflating class TextView
     Caused by: android.view.InflateException: Binary XML file line #43: Error inflating class TextView
     Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
        at android.content.res.TypedArray.getColorStateList(TypedArray.java:546)
        at android.widget.TextView.readTextAppearance(TextView.java:3873)
        at android.widget.TextView.<init>(TextView.java:1208)
        at android.widget.TextView.<init>(TextView.java:1102)
        at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:98)
        at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:94)
        at androidx.appcompat.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:182)
        at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
        at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1378)
        at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1428)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:995)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:859)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:532)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.vanillaplacepicker.presentation.common.VanillaBaseActivity.onCreate(VanillaBaseActivity.kt:17)
        at com.vanillaplacepicker.presentation.common.VanillaBaseViewModelActivity.onCreate(VanillaBaseViewModelActivity.kt:13)
        at android.app.Activity.performCreate(Activity.java:7326)
        at android.app.Activity.performCreate(Activity.java:7317)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3066)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3229)
2019-05-29 13:21:53.067 29436-29436/com.levionsoftware.photos E/AndroidRuntime:     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:6981)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)

My call:

        Intent intent = new VanillaPlacePicker.Builder(activity)
                .withLocation(23.057582, 72.534458)
                .enableMap() // Enable to select place from map
                .build();

        activity.startActivityForResult(intent, REQUEST_PLACE_PICKER);

Gradle:
implementation 'com.github.Mindinventory:VanillaPlacePicker:0.0.6'

I had to do that to eluminate that duplicate error:

    configurations {
        all {
            exclude group: 'com.google.guava', module: 'listenablefuture'
        }
    }

(Source: https://stackoverflow.com/questions/54575037/duplicate-jar-listenablefuture-class-while-migrating-to-new-place-sdk-google)

auto-complete UI should use the Android places SDK

to allow restricting API key usage to authorized apps to prevent/minimize unauthorized usage of our Google Map API keys, auto-complete UI

when i restricted my api key to only allow requests from my app

  • while using the auto-complete activity, i got the error message This IP, site or mobile application is not authorized to use this API key..
  • the map UI still works as expected though.

when investigating the code, i see that:

  • we are using the Places REST API via a web client
    • this is causing Google to reject my API requests because
      • they are "Places REST API web requests"
      • instead of requests made from the Places SDK for Android

No static field tvAddress of type I in class Lcom/vanillaplacepicker

java.lang.NoSuchFieldError: No static field tvAddress of type I in class Lcom/vanillaplacepicker/R$id; or its superclasses (declaration of 'com.vanillaplacepicker.R$id' appears in /data/app/com.instadel-ZuFwShIQZhDmvPYq3zCgRg==/base.apk) at com.vanillaplacepicker.presentation.map.VanillaMapActivity.initViews(VanillaMapActivity.kt:71) at com.vanillaplacepicker.presentation.common.VanillaBaseActivity.onCreate(VanillaBaseActivity.kt:22) at com.vanillaplacepicker.presentation.common.VanillaBaseViewModelActivity.onCreate(VanillaBaseViewModelActivity.kt:13) at android.app.Activity.performCreate(Activity.java:7815) at android.app.Activity.performCreate(Activity.java:7804) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1318) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3349) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3513) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2109) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Pick button is obstructed in full screen phones

When starting
Intent intent = (new VanillaPlacePicker.Builder(Add_Property.this).setTintColor(R.color.colorAccent).enableSatelliteView(true).with(PickerType.MAP).build());

                        startActivityForResult(intent, 100);

The activity starts in full screen, on full screen phones such as S10 Plus , the pick button is behind the fron camera and cannot be clicked.

Automomplete result not getting

Hello,

I'm integrating this awesome library, but unfortunately with MAP_WITH_AUTO_COMPLETE, google auto search fragment open. but when I am searching some places it closed automatically without showing any result.

Please let me know the solution for this.

Thanks

Show selected location from autoComplete in map

When we open auto-complete from map picker, it will be great if u give an option to show the location in the map when selecting from the auto-complete suggestion before delivery it to the intent.

Trying to launch the library error

java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:598)
at android.widget.TextView.readTextAppearance(TextView.java:3975)
at android.widget.TextView.(TextView.java:1027)
at android.widget.TextView.(TextView.java:968)
at android.widget.TextView.(TextView.java:964)
at android.widget.TextView.(TextView.java:960)
at com.google.maps.api.android.lib6.impl.fh.(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100306-0):8)
at com.google.maps.api.android.lib6.impl.bo.az(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100306-0):16)
at com.google.maps.api.android.lib6.impl.cr.o(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100306-0):2)
at com.google.android.gms.maps.internal.o.aX(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100306-0):19)
at ef.onTransact(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100306-0):4)
at android.os.Binder.transact(Binder.java:914)
at com.google.android.gms.internal.maps.zza.zzH(com.google.android.gms:play-services-maps@@18.0.0:2)
at com.google.android.gms.maps.internal.zzk.onCreateView(com.google.android.gms:play-services-maps@@18.0.0:5)
at com.google.android.gms.maps.zzau.onCreateView(com.google.android.gms:play-services-maps@@18.0.0:7)
at com.google.android.gms.dynamic.zad.zab(com.google.android.gms:play-services-base@@18.0.1:2)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaf(com.google.android.gms:play-services-base@@18.0.1:1)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreateView(com.google.android.gms:play-services-base@@18.0.1:2)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(com.google.android.gms:play-services-maps@@18.0.0:1)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1647)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3128)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1432)
at android.app.Activity.performStart(Activity.java:7923)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3364)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2073)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:225)
at android.app.ActivityThread.main(ActivityThread.java:7563)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)

issue with MAP_WITH_AUTO_COMPLETE in java

LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(new LatLng(bottomCoordinate,leftCoordinate)).include(new LatLng(topCoordinate,rightCoordinate));
LatLngBounds cityBounds=builder.build();
Intent locationPickerIntent = new VanillaPlacePicker.Builder(OrderActivity.this)
.withLocation(cityLatitude,cityLongitude)
.with(PickerType.MAP)
.setPickerLanguage(PickerLanguage.ENGLISH)
.setLocationRestriction(cityBounds.northeast,cityBounds.southwest)
.setCountry("IN")
.enableShowMapAfterSearchResult(true)
.setMapType(MapType.NORMAL)
.setMapPinDrawable(R.drawable.ic_placeholder)
.build();
startActivityForResult(locationPickerIntent, requestSenderLocationCode);

Above code works when only map is selected

LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(new LatLng(bottomCoordinate,leftCoordinate)).include(new LatLng(topCoordinate,rightCoordinate));
LatLngBounds cityBounds=builder.build();
Intent locationPickerIntent = new VanillaPlacePicker.Builder(OrderActivity.this)
.withLocation(cityLatitude,cityLongitude)
.with(PickerType.AUTO_COMPLETE)
.setPickerLanguage(PickerLanguage.ENGLISH)
.setLocationRestriction(cityBounds.southwest,cityBounds.northeast)
.setCountry("IN")
.enableShowMapAfterSearchResult(true)
.setMapType(MapType.NORMAL)
.setMapPinDrawable(R.drawable.ic_placeholder)
.build();
startActivityForResult(locationPickerIntent, requestSenderLocationCode);

and this works when using AUTO Complete
Problem is when I type MAP_WITH_AUTO_COMPLETE either search wont work or map wont start!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.