Unable to select a place with Android Place Picker

I am trying to use the location tool in my application. Using this code, I can see that Place Picker shows my current location on the map, but cannot select locations.

 public class MapsActivity extends Activity {

  @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.location_task);
   }

  private static final int REQUEST_PLACE_PICKER = 1;

  public void onPickButtonClick(View v) {
           // Construct an intent for the place picker
    try {
        PlacePicker.IntentBuilder intentBuilder =
                new PlacePicker.IntentBuilder();
        Intent intent = intentBuilder.build(this);
            // Start the intent by requesting a result,
            // identified by a request code.
        startActivityForResult(intent, REQUEST_PLACE_PICKER);
    } catch (GooglePlayServicesRepairableException e) {

    } catch (GooglePlayServicesNotAvailableException e) {

    }
  }
  @Override
   protected void onActivityResult(int requestCode,
                                int resultCode, Intent data) {
       if (requestCode == REQUEST_PLACE_PICKER) {if (resultCode == RESULT_OK) {
        Place place = PlacePicker.getPlace(data, this);
        String toastMsg = String.format("Place: %s", place.getName());
        Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
       }

       } else {
        super.onActivityResult(requestCode, resultCode, data);
     }
}

It displays here

+4
source share

Source: https://habr.com/ru/post/1615946/


All Articles