单个标记运动得很好,但是添加多个标记时效果不佳。
StringRequest stringRequest = new StringRequest(Request.Method.GET, Url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("GET_ASSIGNED_PROJECT", response);
try {
progressDialog.dismiss_dialog();
JSONObject jsonObject1 = new JSONObject(response);
message = jsonObject1.getString("message");
if (message.equals("success")) {
startTimer();
JSONArray jsonArray = jsonObject1.getJSONArray("responseMessg");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
ManagementHomeModel homePageModel = new ManagementHomeModel();
homePageModel.setRegistrationid(jsonObject.getString("Registrationid"));
homePageModel.setName(jsonObject.getString("Name"));
homePageModel.setImageUrl(jsonObject.getString("ImageUrl"));
homePageModel.setLatitude(Double.parseDouble(jsonObject.getString("Latitude")));
homePageModel.setLongitude(Double.parseDouble(jsonObject.getString("Longitude")));
double weblat = jsonObject.getDouble("Latitude");
double weblong = jsonObject.getDouble("Longitude");
latLng = new LatLng(weblat, weblong);
Glide.with(getContext()).load(ServiceUrl.IMAGE_OPEN_URL + jsonObject.getString("ImageUrl")).asBitmap().fitCenter().into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
webmarker = new MarkerOptions().position(new LatLng(weblat, weblong)).icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmapFromView(mCustomMarkerView, bitmap)));
cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10);
mMap.animateCamera(cameraUpdate);
finalmarker = mMap.addMarker(webmarker);
allManagementHomeModels.add(homePageModel);
allHashmarker.put(finalmarker, homePageModel);
}
});
}
} else {
JSONObject object = jsonObject1.getJSONObject("responseMessg");
String responceresult = object.getString("ResposeResult");
Toast.makeText(getContext(), responceresult, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("error", error.getMessage());
progressDialog.dismiss_dialog();
}
});
stringRequest.setRetryPolicy(new DefaultRetryPolicy(20000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
RequestQueue requestQueue = Volley.newRequestQueue(getContext());
requestQueue.add(stringRequest);
final long start = SystemClock.uptimeMillis();
final Interpolator interpolator = new AccelerateDecelerateInterpolator();
final float durationInMs = 3000;
final boolean hideMarker = false;
handler.post(new Runnable() {
long elapsed;
float t;
float v;
@Override
public void run() {
moveMarker = (new ArrayList<Marker>(allHashmarker.keySet())).get(pos);
ManagementHomeModel model = (new ArrayList<ManagementHomeModel>(allHashmarker.values())).get(pos);
startPosition = moveMarker.getPosition();
elapsed = SystemClock.uptimeMillis() - start;
t = elapsed / durationInMs;
v = interpolator.getInterpolation(t);
LatLng currentPosition = new LatLng(
startPosition.latitude * (1 - t) + (finalPosition.getLatitude()) * t,
startPosition.longitude * (1 - t) + (finalPosition.getLongitude()) * t);
moveMarker.setPosition(currentPosition);
if (t < 1) {
// Post again 16ms later.
handler.postDelayed(this, 16);
} else {
if (hideMarker) {
finalmarker.setVisible(false);
} else {
finalmarker.setVisible(true);
}
}
}
});
}
无法同时跟踪所有标记。我需要像ola cab一样同时跟踪所有标记。只能跟踪一个标记,不能超过一个。请帮助我解决此问题。
答案 0 :(得分:1)
在Google地图中添加标记时,在列表中添加所有标记。然后,每当需要更新标记的位置时,只需从列表中找到当前标记并更新位置即可。