1

I created an app that will set the current location, and the text of the location is in the button.. Then, when I click that button, it will show the PlaceAutocomplete. But, what happens is when I clicked that button, it will only show the PlaceAutocomplete for 1 second then closes automatically.. and when I'm looking in my logcat there's no error

I got my API Key from google, and put it in my google_maps_api.xml file.

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">API_KEY</string>

and in my manifest I added this:

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

Now below is the button I created. I'm confused where is my mistake.

b4_sourceButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                Intent i = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY).build(MainPageActivity.this);
                startActivityForResult(i,200);
            } catch (GooglePlayServicesNotAvailableException e) {
                e.printStackTrace();
            } catch (GooglePlayServicesRepairableException e) {
                e.printStackTrace();
            }
        }
    });

It should just show the PlaceAutoComplete on click of my button. That's all..

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ganzo Palumi
  • 77
  • 2
  • 12

2 Answers2

0

do you have initialized the Places ? try this before calling start acitvity

if (!Places.isInitialized()) {
        Places.initialize(this, "AIzaxxxxxxxxxxx");
    }
Kou Peto
  • 237
  • 2
  • 7
0

This may happen due to wrong dependency in gradle or wrong initialise of PLACES API, Kindly follow the instructions in the below link

https://stackoverflow.com/a/55045772/10579969

Navin Kumar
  • 3,393
  • 3
  • 21
  • 46