2017-02-27 1 views
1

전 검색을 완료했으며 답변을 찾지 못했습니다. Similar to this 대체 경로로 색상을 변경하려면 어떻게해야합니까? urlDestination +"&alternatives=true" 해당 코드를 추가하면 가장 짧은 경로와 대체 경로가 표시됩니다. 문제는, 대체 경로의 색상을 특정 색상으로 변경하는 방법을 모르겠습니다. 예 : 최단 경로는 파란색이어야하고 대체 경로는 회색이어야합니다. 도움말이 많이 필요합니다.Android Google지도 대체 경로 및 최단 경로

Something like this... that the alternate routes should be grey

답변

0

확인이 Tutorial

당신은 BelowLine를 추가해야합니다.

polyLineOptions.color(Color.BLUE); 

희망 사항. 도움이 될 수 있습니다.

+0

감사합니다.하지만 내 문제는 무엇입니까. :(모든 경로는 파란색으로 만 설정할 수 있지만 대체 경로의 색상은 변경할 수 없습니다. 이전 코드이기도합니다. 가장 짧은 경로는 파란색으로 지정하고 다른 대체 경로는 다음과 같이 설정합니다. 회색. :( –

0

아주 간단합니다. 나는 당신에게 노선 목록이나 배열이 있다고 생각합니다. 이를 통해 거리 인덱스를 찾으십시오. (대개 첫 번째 것이지만 꼭 확인해야합니다).

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 : 최단 경로를 그릴 필요가 있습니다. 그렇지 않으면 그 경로의 일부가 대체 경로에 의해 겹쳐 질 수 있습니다. 따라서 파란색 부분과 회색 부분 경로가 남습니다.

희망이 있습니다.