Source:
private void showCurrentPlace() { if (mMap == null) { return; } if (mLocationPermissionGranted) { List<Place.Field> placeFields = Arrays.asList(Place.Field.NAME, Place.Field.ADDRESS, Place.Field.LAT_LNG); FindCurrentPlaceRequest request = FindCurrentPlaceRequest.newInstance(placeFields); @SuppressWarnings("MissingPermission") final Task<FindCurrentPlaceResponse> placeResult = mPlacesClient.findCurrentPlace(request); placeResult.addOnCompleteListener (new OnCompleteListener<FindCurrentPlaceResponse>() { @Override public void onComplete(@NonNull Task<FindCurrentPlaceResponse> task) { if (task.isSuccessful() && task.getResult() != null) { FindCurrentPlaceResponse likelyPlaces = task.getResult(); int count; if (likelyPlaces.getPlaceLikelihoods().size() < M_MAX_ENTRIES) { count = likelyPlaces.getPlaceLikelihoods().size(); } else { count = M_MAX_ENTRIES; } int i = 0; mLikelyPlaceNames = new String[count]; mLikelyPlaceAddresses = new String[count]; mLikelyPlaceAttributions = new List[count]; mLikelyPlaceLatLngs = new LatLng[count]; for (PlaceLikelihood placeLikelihood : likelyPlaces.getPlaceLikelihoods()) { mLikelyPlaceNames[i] = (String) placeLikelihood.getPlace().getName(); mLikelyPlaceAddresses[i] = (String) placeLikelihood.getPlace() .getAddress(); mLikelyPlaceAttributions[i] = (List<String>) placeLikelihood.getPlace() .getAttributions(); mLikelyPlaceLatLngs[i] = placeLikelihood.getPlace().getLatLng(); i++; if (i > (count - 1)) { break; } } MapsActivityCurrentPlace.this.openPlacesDialog(); } else { Log.e(TAG, "Exception: %s", task.getException()); } } }); } else { Log.i(TAG, "The user did not grant location permission."); mMap.addMarker(new MarkerOptions() .title(getString(R.string.default_info_title)) .position(mDefaultLocation) .snippet(getString(R.string.default_info_snippet))); getLocationPermission(); } }

Target:
private void showCurrentPlace() { if (mMap == null) { return; } if (mLocationPermissionGranted) { List<Place.Field> placeFields = Arrays.asList(Place.Field.NAME, Place.Field.ADDRESS, Place.Field.LAT_LNG); FindCurrentPlaceRequest request = FindCurrentPlaceRequest.newInstance(placeFields); @SuppressWarnings("MissingPermission") final Task<FindCurrentPlaceResponse> placeResult = mPlacesClient.findCurrentPlace(request); placeResult.addOnCompleteListener (new OnCompleteListener<FindCurrentPlaceResponse>() { @Override public void onComplete(@NonNull Task<FindCurrentPlaceResponse> task) { if (task.isSuccessful() && task.getResult() != null) { FindCurrentPlaceResponse likelyPlaces = task.getResult(); int count; if (likelyPlaces.getPlaceLikelihoods().size() < M_MAX_ENTRIES) { count = likelyPlaces.getPlaceLikelihoods().size(); } else { count = M_MAX_ENTRIES; } int i = 0; mLikelyPlaceNames = new String[count]; mLikelyPlaceAddresses = new String[count]; mLikelyPlaceAttributions = new List[count]; mLikelyPlaceLatLngs = new LatLng[count]; for (PlaceLikelihood placeLikelihood : likelyPlaces.getPlaceLikelihoods()) { mLikelyPlaceNames[i] = placeLikelihood.getPlace().getName(); mLikelyPlaceAddresses[i] = placeLikelihood.getPlace().getAddress(); mLikelyPlaceAttributions[i] = placeLikelihood.getPlace() .getAttributions(); mLikelyPlaceLatLngs[i] = placeLikelihood.getPlace().getLatLng(); i++; if (i > (count - 1)) { break; } } MapsActivityCurrentPlace.this.openPlacesDialog(); } else { Log.e(TAG, "Exception: %s", task.getException()); } } }); } else { Log.i(TAG, "The user did not grant location permission."); mMap.addMarker(new MarkerOptions() .title(getString(R.string.default_info_title)) .position(mDefaultLocation) .snippet(getString(R.string.default_info_snippet))); getLocationPermission(); } }