我正在尝试从附近所有加油站检索燃油价格。我正在使用
PlacesApi
。虽然它检索所有车站信息,如位置、地址、评级等,但它不会返回燃油价格信息。经过一番搜索后,我发现地图 api 不返回燃料 api。有什么办法可以获取此信息吗?
这是我迄今为止所实施的。
List<PlaceDetails> list = new ArrayList<>();
GeocodingResult[] geocodingResults = new GeocodingResult[0];
try {
geocodingResults = GeocodingApi.geocode(context,"Dallas").await();
if (geocodingResults.length > 0) {
LatLng location = geocodingResults[0].geometry.location;
// Perform the Places API request to get the gas stations in Dallas
PlacesSearchResponse searchResponse = PlacesApi.nearbySearchQuery(context, location)
.radius(20000) // Specify the search radius in meters (adjust as needed)
.type(PlaceType.GAS_STATION) // Search for gas stations
.await();
// Iterate through the results and print the gas station names
for (PlacesSearchResult result : searchResponse.results) {
PlaceDetails placeDetails = PlacesApi.placeDetails(context, result.placeId).awaitIgnoreError();
list.add(placeDetails);
System.out.println(result.name);
}
} else {
System.out.println("Unable to geocode Dallas.");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
placeDetails
obj 包含除燃料信息之外的所有信息。
Fuel Prices
数据首先,Google 地图(App)和 Google 地图(API)是不同的平台,因此我们应该期望它们具有不同的特性和功能。
现在,关于在 Places API 中添加 Fuel Price 数据,3 年前(2020 年 7 月)提交了与此相关的 Feature Request,您可以在此链接中查看它:
https://issuetracker.google.com/issues/162155201
请注意,上面的问题跟踪条目是有关上述问题的公共信息的权威来源,所有公开相关的更新都发布在那里。
话虽如此,谷歌目前似乎没有计划将此功能添加到 Places API 中,因为他们将其标记为 不会修复(不可行) 并表示:
我们已审核您的请求,但没有计划实施 目前此功能适用于 Places API。请注意地点 API 旨在为不同支持的对象提供通用详细信息
并且不仅仅特定于place_types
。gas_stations
如果您仍然对此功能感兴趣,您可以在我提供的链接中对功能请求进行投票,并在那里评论您的用例以帮助重新考虑。
我希望这些信息有帮助!
Google Places API(新)现在有燃油价格。 https://developers.google.com/maps/documentation/places/web-service/reference/rest/v1/places#fuelprice