0

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-

5
  • 1
    post your code. The question will be down voted other wise for posting an incomplete question!
    – OBX
    Commented Feb 6, 2017 at 4:30
  • done, i want to retrieve the type using any code rather that create array list
    – seageath
    Commented Feb 6, 2017 at 4:41
  • Are you looking to retrieve the corresponding name for the int values?
    – OBX
    Commented Feb 6, 2017 at 4:47
  • Yes, that's what I'm trying to do, I put on the msgbox for testing purpose
    – seageath
    Commented Feb 6, 2017 at 5:11
  • Thanks all, I got it already. Up and running :)
    – seageath
    Commented Feb 6, 2017 at 8:29

1 Answer 1

3

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

2
  • Thanks @Gavin, my intention is actually to update current marker to custom icon, that's why I tried to get details of the place.
    – seageath
    Commented Feb 6, 2017 at 7:00
  • Got it. Thanks for the answer
    – seageath
    Commented Feb 6, 2017 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.