0

I used google place api for place autocomplete in my app but its automatically close instantly. i tryed both fragment and activity but both close.

code for fragment:

  PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            // TODO: Get info about the selected place.
        }

        @Override
        public void onError(Status status) {
            // TODO: Handle the error.
        }
    });

code for activity:

public void findPlace(View v) {
    try {
        Intent intent =
                new PlaceAutocomplete
                        .IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                        .build(this);
        startActivityForResult(intent, 1);
    } catch (GooglePlayServicesRepairableException e) {
        // TODO: Handle the error.
    } catch (GooglePlayServicesNotAvailableException e) {
        // TODO: Handle the error.
    }
}

// A place has been received; use requestCode to track the request.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1) {
        if (resultCode == RESULT_OK) {
            // retrive the data by using getPlace() method.
            Place place = PlaceAutocomplete.getPlace(this, data);
            //Log.e("Tag", "Place: " + place.getAddress() + place.getPhoneNumber());

           // cLocation.setText(place.getName()+",\n"+
                 //           place.getAddress() +"\n" + place.getPhoneNumber());

        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status status = PlaceAutocomplete.getStatus(this, data);
            // TODO: Handle the error.
            //Log.e("Tag", status.getStatusMessage());

        } else if (resultCode == RESULT_CANCELED) {
            // The user canceled the operation.
        }
    }
}

when i click button new activity open but suddenly close, any reason?

log error:

01-23 13:19:55.614 904-2734/? E/Volley: [146] BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/placesandroid/v1/autocompleteWidget?key=AIzaSyDBQ4zMPX740wUMlIyv6KMrjIY3hj2GN2Y
01-23 13:19:55.624 904-5307/? E/Places: Places API for Android does not seem to be enabled for your app. See https://developers.google.com/places/android/signup for more details.
01-23 13:19:55.625 904-5307/? E/AsyncOperation: serviceID=65, operation=AutocompleteWidgetQuota
                                                OperationException[Status{statusCode=PLACES_API_ACCESS_NOT_CONFIGURED, resolution=null}]
                                                    at anjf.b(:com.google.android.gms@11951034:1)
                                                    at anis.a(:com.google.android.gms@11951034:7)
                                                    at qez.run(:com.google.android.gms@11951034:11)
                                                    at kdf.run(:com.google.android.gms@11951034:26)
                                                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                    at kiq.run(:com.google.android.gms@11951034)
                                                    at java.lang.Thread.run(Thread.java:841)
01-23 13:19:55.626 11046-11046/? E/Places: Autocomplete widget closing due to PLACES_API_ACCESS_NOT_CONFIGURED
01-23 13:20:22.732 21633-21633/? E/cutils-trace: Error opening trace file: No such file or directory (2)
01-23 13:20:22.914 21633-21633/? E/memtrack: Couldn't load memtrack module (No such file or directory)
01-23 13:20:22.914 21633-21633/? E/android.os.Debug: failed to load memtrack module: -2
01-23 13:20:26.396 689-961/? E/Sensors: new acc setDelay handle(0),ns(20000000) err! go to hwmsen
01-23 13:20:26.421 904-1275/? E/CellLocation: create GsmCellLocation
01-23 13:20:27.002 689-700/? E/Sensors: new acc setDelay handle(0),ns(66667000) err! go to hwmsen

i used google map api and manifest:

     <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Dinesh
  • 71
  • 2
  • 10

7 Answers7

1

You probably have to initialize Places

// Initialize Places.
    if (!Places.isInitialized()) {
        Places.initialize(getApplicationContext(),"Your API KEY");
    }
1

Looked this error came due to billing is not enabled in Google Cloud. Try to setup billing, and it will resolve.

dee cue
  • 983
  • 1
  • 7
  • 23
Nitish Kumar
  • 111
  • 3
0

As Per your error Places API not configured correctly.

Follow the steps to configure

https://developers.google.com/places/android-api/

Ramesh sambu
  • 3,577
  • 2
  • 24
  • 39
0

Go to the google developer console and from where you got the api key

Please enable the places API from there as your error suggest.

GoogleDevelopersConsole->SignIn->Dashboard->On the top Enable API's and Services->Click that->Enable google places API

Thats it!!

Shivam Oberoi
  • 1,447
  • 1
  • 9
  • 18
  • do i need another api for google place? i mean i use google map api for map and its working fine. if yes than how? – Dinesh Jan 23 '18 at 08:47
0

problem was I created place API in other project and I used API of google map which was created in different project in google console. The solution is u have to create google place API in the same project if you already using any google API in your app. and use only one in the manifest file.

pankaj sharma
  • 181
  • 2
  • 12
Dinesh
  • 71
  • 2
  • 10
0

This happened you have not includes your api key for google places. Incase you havn't enabled it, just go to google developer console register your application and enable google places api. #Peace

akaMahesh
  • 383
  • 2
  • 9
0

I was using a map on top of the fragment and the behavior was the same. On click of the search, the popup came and gone. It was fixed when I migrated to new APIs, the complete answer I have added in here
Android Place Autocomplete Fragment closing on its own.

If you want to check for yourself here are the links:
Places SDK for Android
Migrating to new Places SDK for Android

Rana Ranvijay Singh
  • 6,055
  • 3
  • 38
  • 54