【问题标题】:Filter the places list which inside the map projection?过滤地图投影内的地点列表?
【发布时间】:2021-01-12 23:58:03
【问题描述】:

我有一个地方List,其中包含Hospital 对象(List<Hospital>)。医院对象包含名称、纬度、经度和手机号码作为属性。如果用户调整屏幕,我会从中得到当前地图投影LatLngBounds。所以现在我想过滤LatLngBounds中的医院,我该如何实现getAvailableHospital()方法?谢谢!

医院对象等级

Class Hospital
{
    private String Name;
    private String Latitude;
    private String Longtitude;
    private String PhoneNumber
}

地图片段内部

@Override
    public void onCameraIdle() {
        LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
        getAvailabelHospitals(bounds.northeast.latitude, bounds.northeast.longitude, bounds.southwest.longitude, bounds.southwest.latitude);
    }

【问题讨论】:

    标签: java android google-maps google-maps-android-api-2


    【解决方案1】:

    LatLngBounds 有一个 contains method,它接受一个 LatLng,如果 LatLng 在边界内则返回 true。

    要生成范围内的医院列表,请检查列表中的每个项目是否包含在范围内。例如:

    List<Hospital> inBounds = hospitals
          .stream()
          .filter(h -> bounds.contains(new LatLng(h.latitude(), h.longitude()))
          .collect(Collectors.toList());
    

    【讨论】:

    • 很高兴得到女程序员的回答!!!,祝你有美好的一天!!!
    【解决方案2】:
    List<fshop> Rlist;
    
    Rlist=new ArrayList<>();
            for(fshop f : mlist)
            {
                LatLng point = new LatLng (Double.parseDouble(f.getLat()), Double.parseDouble(f.getLng()));
                if(bounds.contains(point))
                {
                    Rlist.add(f);
                }
            }
    

    【讨论】:

      猜你喜欢
      • 2012-06-08
      • 2012-07-16
      • 2012-08-14
      • 1970-01-01
      • 2020-08-19
      • 2011-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多