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..
do you have initialized the Places ? try this before calling start acitvity
if (!Places.isInitialized()) {
Places.initialize(this, "AIzaxxxxxxxxxxx");
}
This may happen due to wrong dependency in gradle or wrong initialise of PLACES API, Kindly follow the instructions in the below link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.