PlacesApi 获取经纬度半径范围内的业务类型
PlacesApi get business type within a radius of lat lon
我正在使用以下库从 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?
当然,您可以使用 Java client library 来获得类似于 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);
}
因此,一旦您创建了请求对象,您就可以提供关键字、类型和半径并发送请求。
希望对您有所帮助!
我正在使用以下库从 Google
访问一些位置 APIhttps://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?
当然,您可以使用 Java client library 来获得类似于 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);
}
因此,一旦您创建了请求对象,您就可以提供关键字、类型和半径并发送请求。
希望对您有所帮助!