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" />