아주 간단합니다. 나는 당신에게 노선 목록이나 배열이 있다고 생각합니다. 이를 통해 거리 인덱스를 찾으십시오. (대개 첫 번째 것이지만 꼭 확인해야합니다).
int minDistanceIndex = 0;
int minDistance = Integer.MAX_VALUE;
for(int i = 0; i < routes.size(); i++){
Route route = routes.get(i);
int distance = route.getDistanceValue();
if(distance < minDistance){
minDistance = distance;
minDistanceIndex = i;
}
}
이제 minDistanceIndex를 사용하여 기본 경로 (파란색)와 기타를 회색으로 표시하십시오. 사용자가 단지 구글지도처럼 다른 폴리 라인을 선택하면
PolylineOptions lineOptions;
for (int i = 0; i < routes.size(); i++) {
points = routes.get(i).getPoints();
lineOptions = new PolylineOptions();
// Adding all the points in the route to LineOptions
lineOptions.addAll(points);
if(minDistanceIndex != i) {
lineOptions.width(15);
lineOptions.color(ContextCompat.getColor(getActivity(), android.R.color.darker_gray));
}
lineOptions.clickable(true);
// Drawing polyline in the Google Map for the i-th route
if(map != null) {
polylines.add(map.addPolyline(lineOptions));
map.setOnPolylineClickListener(polylineListener);
}
}
//finally draw the shortest route
lineOptions = new PolylineOptions();
lineOptions.width(18);
lineOptions.color(ContextCompat.getColor(getActivity(), android.R.color.holo_blue_dark));
// Drawing polyline in the Google Map for the i-th route
if(map != null) {
polylines.add(map.addPolyline(lineOptions));
}
당신은 색상을 변경 폴리 라인에 클릭 리스너 상을 추가 할 수 있습니다.
IMP : 최단 경로를 그릴 필요가 있습니다. 그렇지 않으면 그 경로의 일부가 대체 경로에 의해 겹쳐 질 수 있습니다. 따라서 파란색 부분과 회색 부분 경로가 남습니다.
희망이 있습니다.
감사합니다.하지만 내 문제는 무엇입니까. :(모든 경로는 파란색으로 만 설정할 수 있지만 대체 경로의 색상은 변경할 수 없습니다. 이전 코드이기도합니다. 가장 짧은 경로는 파란색으로 지정하고 다른 대체 경로는 다음과 같이 설정합니다. 회색. :( –