过滤地图投影内的地点列表?
Filter the places list which inside the map projection?
我有一个地方 List
,其中包含 Hospital
个对象 (List<Hospital>
)。医院对象包含名称、纬度、经度和手机号码作为属性。如果用户调整屏幕,我会从覆盖区域中获取当前地图投影 LatLngBounds
。所以现在我想过滤 LatLngBounds
里面的医院,我怎样才能实现 getAvailableHospital()
方法?谢谢!
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);
}
LatLngBounds 有一个 contains method 接受 LatLng 并且 returns 如果 LatLng 在范围内则为真。
要生成范围内的医院列表,请检查列表中的每一项是否都包含在范围内。例如:
List<Hospital> inBounds = hospitals
.stream()
.filter(h -> bounds.contains(new LatLng(h.latitude(), h.longitude()))
.collect(Collectors.toList());
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
,其中包含 Hospital
个对象 (List<Hospital>
)。医院对象包含名称、纬度、经度和手机号码作为属性。如果用户调整屏幕,我会从覆盖区域中获取当前地图投影 LatLngBounds
。所以现在我想过滤 LatLngBounds
里面的医院,我怎样才能实现 getAvailableHospital()
方法?谢谢!
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);
}
LatLngBounds 有一个 contains method 接受 LatLng 并且 returns 如果 LatLng 在范围内则为真。
要生成范围内的医院列表,请检查列表中的每一项是否都包含在范围内。例如:
List<Hospital> inBounds = hospitals
.stream()
.filter(h -> bounds.contains(new LatLng(h.latitude(), h.longitude()))
.collect(Collectors.toList());
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);
}
}