Google maps PlacesApi获取纬度半径范围内的业务类型
我正在使用以下库从Google访问一些LocationAPI 我看到下面这样的方法接受两个参数Google maps PlacesApi获取纬度半径范围内的业务类型,google-maps,google-places-api,google-api-java-client,Google Maps,Google Places Api,Google Api Java Client,我正在使用以下库从Google访问一些LocationAPI 我看到下面这样的方法接受两个参数 PlacesApi.nearbySearchQuery(context, location) 但我看不到任何方法可以在lat lon半径范围内获得业务类型 如果我们使用下面的URL directl https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + lat + "," + lng + "&ra
PlacesApi.nearbySearchQuery(context, location)
但我看不到任何方法可以在lat lon半径范围内获得业务类型
如果我们使用下面的URL directl
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + lat + "," + lng + "&radius=100000&type=hospital&name=hospital&key=MYKEY
有没有办法使用库而不是上面的URL?请确保可以使用来获得web服务请求中的结果
请看下面的代码片段,它解释了如何使用这个库
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);
}
所以,一旦创建了请求对象,就可以提供关键字、类型和半径并发送请求
我希望这有帮助 确保可以使用来获得web服务请求中的结果
请看下面的代码片段,它解释了如何使用这个库
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);
}
所以,一旦创建了请求对象,就可以提供关键字、类型和半径并发送请求
我希望这有帮助