Thursday, December 27, 2018

Android: Place Picker to pick address from map

the package needed is,
implementation 'com.google.android.gms:play-services-places:16.0.0'

As given in the references section, if the intent is to show the Android ui to pick the address, then key is probably not required.

Just have the below code

int PLACE_PICKER_REQUEST = 1;
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);



protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == PLACE_PICKER_REQUEST) {
    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();
    }
  }
}



references:
https://developers.google.com/places/android-sdk/placepicker

No comments:

Post a Comment