我想通过搜索片段来找到标记地理位置。片段是板号的地方。我有一个问题,我无法搜索任何其他板号
public class MainActivity extends BaseActivityLocation
implements NavigationView.OnNavigationItemSelectedListener, SearchView.OnQueryTextListener,
SearchView.OnSuggestionListener {
@Override
public boolean onQueryTextSubmit(String query) {
for(Marker m : list) {
if(m.getSnippet().toLowerCase().equals(query)) {
mMapFragment.animateCamera(CameraUpdateFactory.newLatLngZoom(m.getPosition(), 9.0f));
break; // stop the loop
}
}
return false;
}
在另一个班级我添加了一个能够容纳标记的arraylist。它的作用是将所有标记放在此列表中并稍后检索。
public static List<Marker> list;
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 je = response.body().getAsJsonArray().get(i);
JsonObject jo = je.getAsJsonObject();
String plate_n = jo.get("plate_num").toString();
String plate_nString = plate_n;
plate_nString = plate_nString.replace("\"", "");
String plate_num = String.valueOf(plate_nString);
String gps_num = jo.get("gps_num").toString();
String location = jo.get("location").toString();
String date = jo.get("date").toString();
String time = jo.get("time").toString();
String lati = jo.get("lat").toString();
String latiString = lati;
latiString = latiString.replace("\"", "");
String lat = String.valueOf(latiString);
String longi = jo.get("lng").toString();
String longiString = longi;
longiString = longiString.replace("\"", "");
String lng = String.valueOf(longiString);
String engine = jo.get("engine").toString();
String remarks = jo.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);
MarkerOptions opts = createMarker(d, d2, plate_num);
Marker m = mMapFragment.addMarker(opts);
list.add(m);
}