在 Google 个地点中获取当前地点类型 API
Get current place type in Google Places API
我正在使用 Google 个地点 API。
我在我的日志中找到了正确的地点,但我只想要地点类型的名称。假设这是我的输出
Place 'Parque Las Tejas' has likelihood: 0.950000 Type: [69, 1013, 34]
所以,首先我得到了我所在的位置,我所在位置的可能性然后我就用了:
List<Integer> types = placeLikelihood.getPlace().getPlaceTypes();
认为它会 return 喜欢 "park" 或 "square" 但我得到的不是那些数字数组 [69, 1013, 34]
.
根据我read here的说法,有很多类型定义了某个地方。
我想要的是只获得那种类型,所以如果我在一家餐馆,我不想要餐馆的名称,而只想要类型,所以 "Restaurant"
将是我的输出。
我需要这个,因为我想根据用户所在的类型为他们提供选项。
知道我做错了什么吗?
根据文档,您得到的 List<Integer>
实际上是地点类型的 ID:
The elements of this list are drawn from Place.TYPE_*
列表是here. So basically your goal is to convert int code to a string using this list. You can find your solution ,基本上你从Place
class中获取所有字段,找到所有以"TYPE"开头的字段,得到int值并将其与您从 getPlaceTypes()
.
获得的值进行比较
尽管这是旧的 post,但如果您遇到此问题,它会对您有所帮助,
我遇到了这个问题
这是我的方法
List<Place.Type> types = placeLikelihood.getPlace().getTypes();
要获取所有类型,您可以使用 foreach 循环
for(Object type:types){
// get all individual type
}
我正在使用 Google 个地点 API。
我在我的日志中找到了正确的地点,但我只想要地点类型的名称。假设这是我的输出
Place 'Parque Las Tejas' has likelihood: 0.950000 Type: [69, 1013, 34]
所以,首先我得到了我所在的位置,我所在位置的可能性然后我就用了:
List<Integer> types = placeLikelihood.getPlace().getPlaceTypes();
认为它会 return 喜欢 "park" 或 "square" 但我得到的不是那些数字数组 [69, 1013, 34]
.
根据我read here的说法,有很多类型定义了某个地方。
我想要的是只获得那种类型,所以如果我在一家餐馆,我不想要餐馆的名称,而只想要类型,所以 "Restaurant"
将是我的输出。
我需要这个,因为我想根据用户所在的类型为他们提供选项。
知道我做错了什么吗?
根据文档,您得到的 List<Integer>
实际上是地点类型的 ID:
The elements of this list are drawn from Place.TYPE_*
列表是here. So basically your goal is to convert int code to a string using this list. You can find your solution Place
class中获取所有字段,找到所有以"TYPE"开头的字段,得到int值并将其与您从 getPlaceTypes()
.
尽管这是旧的 post,但如果您遇到此问题,它会对您有所帮助, 我遇到了这个问题 这是我的方法
List<Place.Type> types = placeLikelihood.getPlace().getTypes();
要获取所有类型,您可以使用 foreach 循环
for(Object type:types){
// get all individual type
}