英文:
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<Hospital>
). 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<Hospital> inBounds = hospitals
.stream()
.filter(h -> 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<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);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论