Gastón Saillén
Gastón Saillén

Reputation: 13129

Get current place type in Google Places API

I'm working with Google Places API.

I'm getting right the place in my log, but I just want the name of the type of place. Let's say this is my output

Place 'Parque Las Tejas' has likelihood: 0.950000 Type: [69, 1013, 34]

So, at first I get the position where I am, the likelihood of where I am and then I just used:

List<Integer> types = placeLikelihood.getPlace().getPlaceTypes();

thinking it would return like "park" or "square" but instead of that I get those array of numbers [69, 1013, 34].

According to what I read here, there is lots of types that defines a certain place.

What I want is to get that kind of types only, so if I'm at a restaurant I don't want the name of the restaurant but instead just the type, so "Restaurant" will be my output.

I need this because I want to give the user options depending on what type of place they are.

Any idea what I'm doing wrong?

Upvotes: 1

Views: 1537

Answers (2)

emmanuel kofi
emmanuel kofi

Reputation: 141

even though this is an old post, it will help you if you an encountering this issue, i was encountering this issue and here is my approach

 List<Place.Type> types = placeLikelihood.getPlace().getTypes();

to get all the type you can use a foreach loop

    for(Object type:types){
// get all individual type
} 

Upvotes: 1

Suleyman
Suleyman

Reputation: 2943

The List<Integer> that you get is actually the id of type of places, according to the docs:

The elements of this list are drawn from Place.TYPE_*

The list is here. So basically your goal is to convert int code to a string using this list. You can find your solution here, basically you obtain all the fields from the Place class, find all the fields that start with "TYPE", get the int value and compare it to the value that you get from the getPlaceTypes().

Upvotes: 2

Related Questions