如何调整 Google 地图 API 中地点的搜索半径?
How do I adjust the search radius of places in Google Maps API?
发送请求时,我使用 parameter radius=300,它应该显示距我所在位置 300 米半径范围内的地点:
StringBuilder stringBuilder = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
stringBuilder.append("location=").append(mLatitude).append(",").append(mLongitude);
stringBuilder.append("&keyword=пятерочка | магнит");
stringBuilder.append("&language=ru");
stringBuilder.append("&radius=300");
stringBuilder.append("&sensor=true");
距离我所在位置 300 米处的相同 Circle:
Circle circle = mMap.addCircle(new CircleOptions()
.center(latLng)
.radius(300).strokeColor(Color.argb(50, 255, 0, 0))
.fillColor(Color.argb(50, 255, 0, 0)));
文档说返回的值以米为单位,在 300 米的请求中和在 300 米的圆圈中,但实际上我明白了:
image from my device
能否让圆显示的半径与请求的半径一致?
P.S。对不起我的英语不好
This 文档说 -
Results inside of this region will be ranked higher than results
outside of the search circle; however, prominent results from outside
of the search radius may be included.
因此,结论是某些突出位置可能显示在您定义的半径之外。但是,您可以在从 API.
获取所有结果后通过执行循环来排除边界外的那些
- 在您的依赖项中包含 Map-utils -
implementation 'com.google.maps.android:android-maps-utils:0.5+'
- 计算每个地点与中心的距离,并为边界内的地点放置标记
for (Place place: allPlaces) {
float distance = (float) SphericalUtil.computeDistanceBetween(centreLatLng, place.getLatLng());
if (distance <= 300) {
Marker placeMarker = googleMap.addMarker(new MarkerOptions()
.position(place.getLatLng())
.title(place.getName())
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.anchor(0.5 f, 1.0 f));
}
}
发送请求时,我使用 parameter radius=300,它应该显示距我所在位置 300 米半径范围内的地点:
StringBuilder stringBuilder = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
stringBuilder.append("location=").append(mLatitude).append(",").append(mLongitude);
stringBuilder.append("&keyword=пятерочка | магнит");
stringBuilder.append("&language=ru");
stringBuilder.append("&radius=300");
stringBuilder.append("&sensor=true");
距离我所在位置 300 米处的相同 Circle:
Circle circle = mMap.addCircle(new CircleOptions()
.center(latLng)
.radius(300).strokeColor(Color.argb(50, 255, 0, 0))
.fillColor(Color.argb(50, 255, 0, 0)));
文档说返回的值以米为单位,在 300 米的请求中和在 300 米的圆圈中,但实际上我明白了:
image from my device
能否让圆显示的半径与请求的半径一致?
P.S。对不起我的英语不好
This 文档说 -
Results inside of this region will be ranked higher than results outside of the search circle; however, prominent results from outside of the search radius may be included.
因此,结论是某些突出位置可能显示在您定义的半径之外。但是,您可以在从 API.
获取所有结果后通过执行循环来排除边界外的那些- 在您的依赖项中包含 Map-utils -
implementation 'com.google.maps.android:android-maps-utils:0.5+'
- 计算每个地点与中心的距离,并为边界内的地点放置标记
for (Place place: allPlaces) {
float distance = (float) SphericalUtil.computeDistanceBetween(centreLatLng, place.getLatLng());
if (distance <= 300) {
Marker placeMarker = googleMap.addMarker(new MarkerOptions()
.position(place.getLatLng())
.title(place.getName())
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.anchor(0.5 f, 1.0 f));
}
}