发送请求时,我使用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");

同样的Circle距离我的位置300米:
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
是否可以使圆显示的半径与请求的半径匹配?
对不起,我英语不好

最佳答案

This文件上说-
此区域内的结果将排名高于结果
在搜索圈之外;但是,来自外部的显著结果
搜索半径的。
因此,结论是一些突出的位置可能显示在你定义的半径之外。但是,在从api获得所有结果之后,可以通过实现循环来排除边界之外的那些结果。
在依赖项中包含映射实用程序-
实现“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));
    }
}

10-07 19:15
查看更多