过滤地点列表,仅保留位于地图投影内的部分。

huangapple go评论61阅读模式
英文:

Filter the places list which inside the map projection?

问题

我有一个包含Hospital对象(List<Hospital>)的地点列表。Hospital对象包含名称、纬度、经度和手机号作为属性。如果用户调整了屏幕,我会从中获取当前地图投影的LatLngBounds,从中获得覆盖区域。现在,我想要过滤出位于该LatLngBounds内的医院,我该如何实现getAvailableHospital()方法?谢谢!

医院对象类

class Hospital {
    private String Name;
    private String Latitude;
    private String Longitude;
    private String PhoneNumber;
}

地图片段内部

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

请注意,我已经更正了医院对象类中的拼写错误,将"Longtitude"更正为"Longitude"。如果你需要进一步的代码实现,请提出具体问题。

英文:

I have a places List Which contains Hospital object(List&lt;Hospital&gt;). Hospital objects contain Name, latitude, longitude, and mobile number as an attribute. If the user adjusts the screen I get the current map projection LatLngBounds from that I got covered area. So Now I want to filter the Hospitals Which inside the that LatLngBounds, How can I implement getAvailableHospital() method? Thank you!

> Hospital Object Class

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

> Inside the Map Fragment

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

答案1

得分: 2

LatLngBounds有一个contains方法,它接受一个LatLng参数,并在LatLng在范围内时返回true。

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

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

LatLngBounds has a contains method that takes a LatLng and returns true if the LatLng is within the bounds.

To generate a list of hospitals within the bounds, check whether each item in your list is contained within the bounds. For example:

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

答案2

得分: 0

Sure, here is the translated code:

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);
    }
}
英文:
List&lt;fshop&gt; Rlist;

Rlist=new ArrayList&lt;&gt;();
        for(fshop f : mlist)
        {
            LatLng point = new LatLng (Double.parseDouble(f.getLat()), Double.parseDouble(f.getLng()));
            if(bounds.contains(point))
            {
                Rlist.add(f);
            }
        }

huangapple
  • 本文由 发表于 2020年9月27日 11:49:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/64084603.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定