seageath
seageath

Reputation: 17

Convert Google Place Types into String

I'm working on my code to check the types of the place base on place details following this document (https://developers.google.com/android/reference/com/google/android/gms/location/places/Place).

I manage the value from List, the question is how I can display the string for example place a is restaurant, place be is bank from the class. Or should I create an array based on the document? Please advise.

final Place place = PlacePicker.getPlace(this, data);
final List<Integer> types = place.getPlaceTypes();
Toast.makeText(getApplicationContext(), types.get(0).toString(), Toast.LENGTH_SHORT).show();

Regards, -sea-

Upvotes: 0

Views: 693

Answers (1)

Gavin Harris
Gavin Harris

Reputation: 712

You could do something as crazy as:

    int myPlaceType = 1;

    Field[] fields = Place.class.getDeclaredFields();

    for (Field field : fields) {
        Class<?> type = field.getType();

        if(type == int.class) {
            try {
                if(myPlaceType == field.getInt(null)) {
                    Log.i("Testing", "onCreate: " + field.getName());
                    break;
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }

This will print TYPE_ACCOUNTING to your Android console.

Where myPlaceType is the int place type... Not perfect, and I hope someone has a better suggestion!

Gav

Upvotes: 3

Related Questions