Wednesday, 1 June 2016

PlacePicke Example Android


Step 1:

add in android app gradle:

compile 'com.google.android.gms:play-services-nearby:8.4.0'compile 'com.google.android.gms:play-services-location:8.4.0'

First of all need to API key and Enable Google Place API to search and get place details. Add your API key to your app manifest ,need to replacing YOUR_API_KEY with your own API key:
<application>
  ...
  <meta-data
      android:name="com.google.android.geo.API_KEY"
      android:value="YOUR_API_KEY"/>
</application>
Step 2:
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();
    }
  }
}
you can see given link for customize ui:
https://developers.google.com/places/android-api/placepicker#add

No comments:

Post a Comment