我在如何使用onQueryTextSubmit
和onQueryTextChange
方面遇到问题我想要的是使用我的addMarker上的代码段来获取可搜索的版号。我现在的问题是我在onQueryTextSubmit下是一个区分大小写的错误值。我在列表中添加了我的标记,I am getting always the last value not all values.
请。帮助
标记
public void vehicleRequest_validate() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
networkAPI = retrofit.create(NetworkAPI.class);
VehicleRequestPojo loginRequest = new VehicleRequestPojo(MainActivity.ucsi_num, client_table, markutype);
Call<JsonElement> call = networkAPI.loginRequest(loginRequest);
call.enqueue(new Callback<JsonElement>() {
@Override
public void onResponse(Call<JsonElement> call, Response<JsonElement> response) {
// success response
if (response.body().isJsonArray()) {
JsonArray objectWhichYouNeed = response.body().getAsJsonArray();
System.out.println(objectWhichYouNeed + " Object");
for (int i = 0; i < response.body().getAsJsonArray().size(); i++) {
JsonElement plate_num_array = response.body().getAsJsonArray().get(i);
JsonObject plate_num_obj = plate_num_array.getAsJsonObject();
String plate_n = plate_num_obj.get("plate_num").toString();
String plate_nString = plate_n;
plate_nString = plate_nString.replace("\"", "");
String plate_num = String.valueOf(plate_nString);
JsonElement gps_num_array = response.body().getAsJsonArray().get(i);
JsonObject gps_num_obj = gps_num_array.getAsJsonObject();
String gps_num = gps_num_obj.get("gps_num").toString();
JsonElement location_array = response.body().getAsJsonArray().get(i);
JsonObject location_obj = location_array.getAsJsonObject();
String location = location_obj.get("location").toString();
JsonElement date_array = response.body().getAsJsonArray().get(i);
JsonObject date_obj = date_array.getAsJsonObject();
String date = date_obj.get("date").toString();
JsonElement time_array = response.body().getAsJsonArray().get(i);
JsonObject time_obj = time_array.getAsJsonObject();
String time = time_obj.get("time").toString();
JsonElement lat_array = response.body().getAsJsonArray().get(i);
JsonObject lat_obj = lat_array.getAsJsonObject();
String lati = lat_obj.get("lat").toString();
String latiString = lati;
latiString = latiString.replace("\"", "");
String lat = String.valueOf(latiString);
JsonElement lng_array = response.body().getAsJsonArray().get(i);
JsonObject lng_obj = lng_array.getAsJsonObject();
String longi = lng_obj.get("lng").toString();
String longiString = longi;
longiString = longiString.replace("\"", "");
String lng = String.valueOf(longiString);
JsonElement engine_array = response.body().getAsJsonArray().get(i);
JsonObject engine_obj = engine_array.getAsJsonObject();
String engine = engine_obj.get("engine").toString();
JsonElement remarks_array = response.body().getAsJsonArray().get(i);
JsonObject remarks_obj = remarks_array.getAsJsonObject();
String remarks = remarks_obj.get("remarks").toString();
if (lat != null && !lat.equals("null")
&& (lng != null && !lng.equals("null")
|| (lat != "" && lat != "")
&& lng != "") && (lng != "")) {
Double d = Double.parseDouble(lat);
Double d2 = Double.parseDouble(lng);
createMarker(d, d2, plate_num);
}
}
} else {
System.out.println("Not a JSONArray.");
}
}
@Override
public void onFailure(Call<JsonElement> call, Throwable t) {
// failure response
System.out.println(call.toString());
}
});
}
public void createMarker(Double latitude, final Double longitude, String Plate_num) {
BitmapDescriptor image = BitmapDescriptorFactory.fromResource(R.drawable.bus);
list = new ArrayList<Marker>();
Marker marker = mMapFragment.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title("Plate No.")
.snippet(Plate_num)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
list.add(marker);
/* mMapFragment.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.anchor(0.5f, 0.5f)
.title("Plate No.")
.snippet(Plate_num)
.icon(image));*/
mMapFragment.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
marker.hideInfoWindow();
}
});
mMapFragment.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 9.0f));
mMapFragment.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(final Marker marker) {
vm = new VehicleMap();
vm.setSnippet(marker.getSnippet());
vm.setPlate_num(marker.getSnippet());
latitudeG = marker.getPosition().latitude;
longitudeG = marker.getPosition().longitude;
marker.showInfoWindow();
BottomSheetDialogFragment bottomSheetDialogFragment = new BottomSheetModalFragment(activity);
bottomSheetDialogFragment.show(getFragmentManager(), bottomSheetDialogFragment.getTag());
return true;
}
});
}
public void onMapReady(GoogleMap googleMap) {
mMapFragment = googleMap;
/* LatLng latlong = new LatLng(12.405888, 123.273419);
CameraUpdate cameraPosition = CameraUpdateFactory.newLatLngZoom(latlong, 16);
mMap.moveCamera(cameraPosition);
mMap.animateCamera(cameraPosition);*/
new GetVehicles().execute();
mMapFragment.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(12.405888, 123.273419), 6));
// mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(12.405888, 123.273419), 13));
setUpMap();
}
这里我要传递search title =“Plate No.”的值LatLng值的纬度和经度。
public boolean onQueryTextSubmit(String query) {
centerMarker(query);
for(Marker m : list) {
System.out.println(m.getSnippet() + m.getTitle() + m.getPosition() + " snippet");
if(m.getSnippet().equals(query)) {
Toast.makeText(this, "You searched for: " + query , Toast.LENGTH_SHORT).show();
mMapFragment.animateCamera(CameraUpdateFactory.newLatLngZoom(m.getPosition(), 9.0f));
break; // stop the loop
}
}
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
答案 0 :(得分:0)
我总是得到最后一个值而不是所有值。
您只能获得一个值(...可能),因为您在每次调用createMarker(d, d2, plate_num)
public void createMarker(Double latitude, final Double longitude, String Plate_num) {
BitmapDescriptor image = BitmapDescriptorFactory.fromResource(R.drawable.bus);
// list = new ArrayList<Marker>(); // Stop doing this!