在我的代码中,医生显示在谷歌地图上,每位医生都有一些属性 用户按任何属性或属性进行搜索, 如果用户输入地址" USA"专业化是" Heart"然后只会显示那些医生,其地址和专业化如下:
因此用户可以输入许多组合 和 我无法理解如何实现这些过滤器,
我的代码是
private void showdoctorresult() {
final String selectedspec = dr_spec_spiner.getSelectedItem().toString();
final String selecedgender = gender_spiner.getSelectedItem().toString();
final String enteredaddress = mapsearchaddress.getText().toString();
final String enteredfee = mapsearchfee.getText().toString();
final String enteredtime = mapsearchtime.getText().toString();
DatabaseReference doctordRef = FirebaseDatabase.getInstance().getReference().child("Users").child("Doctor");
mMap.clear();
doctordRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
// SaveDonorData doctordata = dataSnapshot.getValue(SaveDonorData.class);
String latitude = child.child("latitude").getValue().toString();
String longitude = child.child("longitude").getValue().toString();
String donarname = child.child("user_name").getValue().toString();
String drspec = child.child("specialization").getValue().toString();
String draddress = child.child("user_address").getValue().toString();
String dr_time = child.child("time").getValue().toString();
String dr_fee = child.child("fee").getValue().toString();
String dr_gender = child.child("gender").getValue().toString();
spec.add(drspec);
double loclatitude = Double.parseDouble(latitude);
double loclongitude = Double.parseDouble(longitude);
LatLng cod = new LatLng(loclatitude, loclongitude);
if(!selectedspec.matches("") || !selecedgender.matches("") || !enteredaddress.matches("") || !enteredfee.matches("")|| !enteredtime.matches("")){
if(selectedspec.toLowerCase().contains(drspec.toLowerCase()) && enteredaddress.toLowerCase().contains(draddress.toLowerCase()) && selecedgender.matches(dr_gender) && enteredfee.matches(dr_fee) && enteredtime.matches(dr_time)){
mMap.addMarker(new MarkerOptions().position(cod).title(donarname));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(cod,15));
}
} else
if(!selectedspec.matches("") || !selecedgender.matches("") || !enteredaddress.matches("") || !enteredfee.matches("") ){
if(selectedspec.toLowerCase().contains(drspec.toLowerCase())&& enteredaddress.toLowerCase().contains(draddress.toLowerCase()) && selecedgender.matches(dr_gender) && enteredfee.matches(dr_fee) ){
mMap.addMarker(new MarkerOptions().position(cod).title(donarname));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(cod,15));
}
}else
if(!selectedspec.matches("") || !selecedgender.matches("") || !enteredaddress.matches("") ){
if(selectedspec.toLowerCase().contains(drspec.toLowerCase()) && selecedgender.matches(dr_gender)&& enteredaddress.toLowerCase().contains(draddress.toLowerCase()) ){
mMap.addMarker(new MarkerOptions().position(cod).title(donarname));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(cod,15));
}
}else
if(!selectedspec.matches("") || !selecedgender.matches("") ){
if(selectedspec.toLowerCase().contains(drspec.toLowerCase()) && selecedgender.matches(dr_gender) ){
mMap.addMarker(new MarkerOptions().position(cod).title(donarname));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(cod,15));
}
}else
if(!selectedspec.matches("") ){
if(selectedspec.toLowerCase().contains(drspec.toLowerCase()) ){
mMap.addMarker(new MarkerOptions().position(cod).title(donarname));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(cod,15));
}
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
我如何制作逻辑来搜索医生,用户可以输入任何字段并获得结果 请回答我 在此先感谢
答案 0 :(得分:0)
进行sql查询并触发firebase存储,如下面的代码,你可以改变。
private void sqlQuery(){
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
Query query = reference.child("usersDb").child("UserTable").orderByChild("email").equalTo("vikas@gmail.com");
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
for (DataSnapshot issue : dataSnapshot.getChildren()) {
Log.d("Value::",issue.getValue(User.class).email);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
答案 1 :(得分:0)
所以回答的第一个问题(我认为你有)将是"是用户 查询' AND'或者'或者'" - 就像我在寻找所有女性,心脏病专家一样,' 或者我正在寻找所有的女医生或心脏病专家#39;
所以假设它是一个AND,每条记录的逻辑如下:
onDataChange
// set flags for each filter based on if any selection made
set 'specialtySet' to true if selectedSpec not empty string.
set 'genderSet' to true if selectedGender not empty string.
// repeat for each filter...
set lastMarkerLoc = null
for each child loop
set 'addMarker' to false
if 'specialtySet'
if specialty matches
set 'addMarker' to true
else
// This is the 'AND' all specified filters must pass test.
// If instead you wanted 'OR' then eliminate the 'continue'
continue // loop
endif
endif
if 'genderSet'
if gender matches
set 'addMarker' to true
else
continue // loop
endif
endif
//... repeat similar logic for each filter
if 'addMarker' is true
addMarker()
// no need to move camera for every result
set 'lastMarkerLoc' to this location
endif
endloop
// zoom camera
if 'lastMarkerLoc' != null
zoom camera to 'lastMarkerLoc'
endif
end onDataChange
PS - 修复' SEARCH'按钮。