Android, Java + Google Map: прямые маршруты бесполезны. Можно ли их устранить?JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Android, Java + Google Map: прямые маршруты бесполезны. Можно ли их устранить?

Сообщение Anonymous »

Видео проблемы
Прямые маршруты бесполезны. Можно ли их устранить? есть прямые линии, которые мне не нужны.
Ввод от rest_api, это простой json по этой ссылке:
https://drive. google.com/file/d/1S2_xOB9Bj6EqiFwuRNGV5JvrjPjZoQD0/view?usp=sharing
Вывод: карта с маркерами и **БЕЗ ЛЮБЫХ прямых линий. **.
Код:

Код: Выделить всё

onMapReady(@NonNull GoogleMap map) {
googleMap = map;
googleMap.getUiSettings().setMapToolbarEnabled(false);
googleMap.getUiSettings().setZoomControlsEnabled(false);

routePoints = new ArrayList();
noRoutePoints = new ArrayList();

String idTappaSelezionata = MainActivity.idUltimaTappaSelezionata;

if (idTappaSelezionata != null) {
mapView.setVisibility(View.GONE);

StringRequest getPercorsoRequest = new StringRequest(Request.Method.POST, Config.GET_PERCORSO_URL,
response -> {
Logger.show("Mappa getData response: " + response + " | Url: " + Config.GET_PERCORSO_URL);

try {
JSONObject responseObject = new JSONObject(response);
JSONArray percorsoArray = responseObject.getJSONArray("percorso");

if (percorsoArray.length() == 0) {
clearRoutes();
} else {
parseAndDisplayRoute(percorsoArray);
}

mapView.setVisibility(View.VISIBLE);
} catch (JSONException e) {
// handle exception
}
},
error -> {
// handle error
}) {
@Override
protected Map getParams() {
Map params = new HashMap();
params.put("user_id", MainActivity.userLoggedId);
params.put("id_tappa", idTappaSelezionata);
params.put("id_via", MainActivity.idUltimaViaSelezionata);
return params;
}
};

SingletonVolley.getInstance(getActivity()).addToRequestQueue(getPercorsoRequest);
} else {
showNoRouteDialog();
}
}

private void clearRoutes() {
getActivity().runOnUiThread(() -> {
routePoints.clear();
noRoutePoints.clear();
});
}

private void parseAndDisplayRoute(JSONArray percorsoArray) throws JSONException {
for (int i = 0; i < percorsoArray.length(); i++) {
Gson gson = new Gson();
String tmpPercorso = percorsoArray.getJSONObject(i).toString();
Percorso newP = gson.fromJson(tmpPercorso, Percorso.class);

if ("rosso".equals(newP.getColore())) {
routePoints.add(new LatLng(newP.getLatitude(), newP.getLongitude()));
} else if ("blu".equals(newP.getColore())) {
noRoutePoints.add(new LatLng(newP.getLatitude(), newP.getLongitude()));
}
}

getActivity().runOnUiThread(() -> {
if (!routePoints.isEmpty()) {
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(routePoints.get(0), 14));
}

if (routePoints.size() > 1 && noRoutePoints.size() > 1) {
addPolylines();
}

addMarker();
setPolylineClickListener();
});
}

private void addPolylines() {
List percorso = PolyUtil.simplify(routePoints, 0.0001); // Adjusted tolerance

PolylineOptions percorsoPolyline = new PolylineOptions()
.addAll(percorso)
.clickable(true)
.width(10)
.color(Color.RED);

googleMap.addPolyline(percorsoPolyline);

// List simplifiedNoRoute = PolyUtil.simplify(noRoutePoints, 0.0001);  // Adjusted tolerance

/*PolylineOptions polylineOptionsRosso = new PolylineOptions()
.addAll(simplifiedRoute)
.clickable(true)
.width(10)
.color(Color.RED);

googleMap.addPolyline(polylineOptionsRosso);

PolylineOptions polylineOptionsBlu = new PolylineOptions()
.addAll(simplifiedNoRoute)
.clickable(true)
.width(10)
.color(Color.BLUE);

googleMap.addPolyline(polylineOptionsBlu);*/

getExperiences(googleMap);
}

private void addMarker() {
LatLng markerMe = routePoints.get(0);
int customMarkerHeight = 100;
int customMarkerWidth = 100;
BitmapDrawable bitmapDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.me);
Bitmap customMarkerBitmap = Bitmap.createScaledBitmap(bitmapDrawable.getBitmap(), customMarkerWidth, customMarkerHeight, false);
BitmapDescriptor customMarkerMe = BitmapDescriptorFactory.fromBitmap(customMarkerBitmap);

MarkerOptions markerOp = new MarkerOptions()
.position(markerMe)
.icon(customMarkerMe)
.title("Marker " + getId());

googleMap.addMarker(markerOp);
}

private void setPolylineClickListener() {
googleMap.setOnPolylineClickListener(polyline -> {
List path = polyline.getPoints();
String navigationUri = "http://maps.google.com/maps?daddr=" + path.get(path.size() - 1).latitude + "," + path.get(path.size() - 1).longitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(navigationUri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
});
}

private void showNoRouteDialog() {
mapView.setVisibility(View.GONE);

String message = "Non è stato selezionato nessun percorso. Premere OK per scegliere un percorso.";
androidx.appcompat.app.AlertDialog.Builder dialog = new androidx.appcompat.app.AlertDialog.Builder(getActivity());
dialog.setTitle("Le Vie di Francesco");
dialog.setMessage(message);

dialog.setPositiveButton("OK", (dialogInterface, i) -> {
((MainActivity) getActivity()).caricaFragment("menu_home", new Vie(), "Vie");
});
dialog.setCancelable(false);
dialog.show();
}

Где моя беда?

Подробнее здесь: https://stackoverflow.com/questions/787 ... -eliminate
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»