【问题标题】:PlacesApi get business type within a radius of lat lonPlacesApi 获取纬度半径内的业务类型
【发布时间】:2018-04-03 21:36:41
【问题描述】:
我正在使用以下库从 Google 访问一些位置 API
https://github.com/googlemaps/google-maps-services-java
我看到下面的方法接受两个参数
PlacesApi.nearbySearchQuery(context, location)
但我没有看到任何方法可以在纬度半径范围内获取业务类型。
如果我们像下面这样直接使用 URL
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + lat + "," + lng + "&radius=100000&type=hospital&name=hospital&key=MYKEY
有什么方法可以使用库而不是上面的 URL?
【问题讨论】:
标签:
google-maps
google-places-api
google-api-java-client
【解决方案1】:
当然,您可以使用Java client library 来获得类似于 Web 服务请求的结果。
看看下面解释如何使用这个库的代码sn-p
GeoApiContext context = new GeoApiContext.Builder()
.apiKey("AIza......")
.build();
NearbySearchRequest req = PlacesApi.nearbySearchQuery(context, new com.google.maps.model.LatLng(41.385064,2.173403));
try {
PlacesSearchResponse resp = req.keyword("pizza")
.type(PlaceType.RESTAURANT)
.radius(2000)
.await();
if (resp.results != null && resp.results.length > 0) {
for (PlacesSearchResult r : resp.results) {
PlaceDetails details = PlacesApi.placeDetails(context,r.placeId).await();
String name = details.name;
String address = details.formattedAddress;
URL icon = details.icon;
double lat = details.geometry.location.lat;
double lng = details.geometry.location.lng;
String vicinity = details.vicinity;
String placeId = details.placeId;
String phoneNum = details.internationalPhoneNumber;
float rating = details.rating;
}
}
} catch(Exception e) {
Log.e(TAG, "Error getting places", e);
}
因此,一旦您创建了请求对象,您就可以提供关键字、类型和半径并发送请求。
我希望这会有所帮助!