Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android PlaceFilter usage with Google Places API

I am trying to use the Google Places API and I would like to filter my search to only gym types.

I am using the code given at https://developers.google.com/places/

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
    && resultCode == Activity.RESULT_OK) {

    // The user has selected a place. Extract the name and address.
    final Place place = PlacePicker.getPlace(data, this);

    final CharSequence name = place.getName();
    final CharSequence address = place.getAddress();
    String attributions = PlacePicker.getAttributions(data);
    if (attributions == null) {
        attributions = "";
    }

    mViewName.setText(name);
    mViewAddress.setText(address);
    mViewAttributions.setText(Html.fromHtml(attributions));

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

What I was trying to do was to create a filter like below and somehow add that (placeFilter) to the intent.

PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
PlaceFilter placeFilter;
ArrayList<String> restictToGyms = new ArrayList<>();
restictToGyms.add("44");
placeFilter = new PlaceFilter(false, restictToGyms);
intent.SOMEHOWADD(placeFilter);
Intent intent = intentBuilder.build(this);

But I am not sure how to add this filter to the intent. In fact I am not sure if this is the right way of doing it. Any pointers will be appreciated. Thanks!

like image 464
nevzo Avatar asked Apr 11 '15 23:04

nevzo


1 Answers

I've been looking to do the same thing. Unfortunately it doesn't seem possible- the PlaceFilter takes place ids, not types. The class PlaceFilter is final so it cannot be extended (I hate it when API writers make classes final, there's almost never a reason to do it). You need to actually make the call and do the filtering via a loop after the result returns.

like image 131
Gabe Sechan Avatar answered Oct 13 '22 23:10

Gabe Sechan