Android Android Places API edit

Getting Current Places by Using Places API

You can get the current location and local places of user by using the Google Places API.

Ar first, you should call the PlaceDetectionApi.getCurrentPlace() method in order to retrieve local business or other places. This method returns a PlaceLikelihoodBuffer object which contains a list of PlaceLikelihood objects. Then, you can get a Place object by calling the PlaceLikelihood.getPlace() method.

Important: You must request and obtain the ACCESS_FINE_LOCATION permission in order to allow your app to access precise location information.

private static final int PERMISSION_REQUEST_TO_ACCESS_LOCATION = 1;

private TextView txtLocation;
private GoogleApiClient googleApiClient;

protected void onCreate(@Nullable Bundle savedInstanceState) {

    txtLocation = (TextView) this.findViewById(;
    googleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)


private void getCurrentLocation() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        Log.e(LOG_TAG, "Permission is not granted");

        ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION},PERMISSION_REQUEST_TO_ACCESS_LOCATION);

    Log.i(LOG_TAG, "Permission is granted");
    PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace(googleApiClient, null);
    result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
        public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
            Log.i(LOG_TAG, String.format("Result received : %d " , likelyPlaces.getCount() ));
            StringBuilder stringBuilder = new StringBuilder();

            for (PlaceLikelihood placeLikelihood : likelyPlaces) {
                stringBuilder.append(String.format("Place : '%s' %n",

public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
            // If the request is cancelled, the result arrays are empty.
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            } else {
                // Permission denied, boo!
                // Disable the functionality that depends on this permission.

        // Add further 'case' lines to check for other permissions this app might request.

public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    Log.e(LOG_TAG, "GoogleApiClient connection failed: " + connectionResult.getErrorMessage());

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
64 Menu
105 Android Places API
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close