반응형
네이버 v3 지도에 다중 경로 그리기.
PathOverlayMultipartPathOverlay와 Marker를 활용해서, 경로를 그리고, 마커를 표시함.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | //전역 변수 private ArrayList<GPSLocation> arrGpsLocation; private List<LatLng> lstLatLng; //최초 조회된 좌표, 우후 추가 된 부분만 조회할 경우 구분하기위해서 필요함. private static NaverMap nMap; private static PathOverlay path; //단일 경로 private MultipartPathOverlay multipartPath; //다중경로 //전역 변수 public void MapDrawAdd(ArrayList<GPSLocation> arrAddLocation) { //add marker int nCnt = 0 ; int moveDistance = 0 ; Marker marker; LatLng temp = new LatLng( 0 , 0 ); try { if (arrAddLocation.size() > 2 ) { //기초 데이터 설정 부분 상황에 따라 다르기에 참고만.. if (lstAddLatLng == null ) { lstAddLatLng = new ArrayList<>(); //다중 마커이다 보니, 경로가 이어지지 않음. 그래서 이어주기 위해서, 앞 좌표 레이어를 마지막 값을 2번째 좌표에 다시 넣어줌 //안해도 상관없음. lstAddLatLng.add(lstLatLng.get(lstLatLng.size() - 1 )); } for ( int i = 0 ; i < arrAddLocation.size(); i++) { //맵에 추가. arrGpsLocation.add(arrAddLocation.get(i)); temp = new LatLng(arrAddLocation.get(i).getLatitude(), arrAddLocation.get(i).getLongitude()); //추가 된 좌표 lstAddLatLng.add(temp); moveDistance += arrAddLocation.get(i).getDistance(); if (nCnt == 200 || i == 0 ) //추가된 좌표와 200개마다 마커 추가 { marker = new Marker(); marker.setPosition(temp); //marker.setAnchor(new PointF(1, 1)); marker.setWidth(Marker.SIZE_AUTO); marker.setHeight(Marker.SIZE_AUTO); marker.setCaptionText( "추가 : " + arrAddLocation.get(i).getPositionTime()); marker.setCaptionRequestedWidth( 200 ); marker.setCaptionTextSize( 10 ); marker.setIcon(MarkerIcons.YELLOW); marker.setSubCaptionText(String.valueOf(moveDistance) + "M" ); marker.setSubCaptionColor(Color.BLUE); marker.setSubCaptionTextSize( 10 ); marker.setMap(nMap); nCnt = 0 ; moveDistance = 0 ; } nCnt++; } //여기서 부터가 지도. path.setMap( null ); //기존에 그려진 경로를 지워줌., //다중 경로를 생성함. 이미 생성되어 있다면, 초기화 if (multipartPath == null ) multipartPath = new MultipartPathOverlay(); else multipartPath.setMap( null ); multipartPath.setCoordParts(Arrays.asList(lstLatLng, lstAddLatLng)); //다중경로 넣기 //경로가 그려질 선 색상 설정. multipartPath.setColorParts(Arrays.asList( new MultipartPathOverlay.ColorPart(Color.RED, Color.RED, Color.RED, Color.RED), new MultipartPathOverlay.ColorPart(Color.YELLOW, Color.YELLOW, Color.YELLOW, Color.YELLOW) )); multipartPath.setMap(nMap); //경로 그리기. CameraPosition nCameraPosition = new CameraPosition(lstAddLatLng.get(lstAddLatLng.size()- 1 ), 15 ); //카메라 위치 이동 nMap.setCameraPosition(nCameraPosition); } } catch (Exception e) { ErrorMessage( "NaverMap MapDrawAdd(String data) " + e.getMessage()); } } |
반응형
'Android' 카테고리의 다른 글
android sleep (1) | 2020.08.18 |
---|---|
안드로이드 해시키 코드로 조회 (0) | 2019.10.20 |
네이버 플랫폼 맵 PathOverlay활용. 경로 그리기 (1) | 2019.10.11 |
androidx.appcompat.widget.toolbar vs android.support.v7.widget.toolbar (0) | 2019.10.05 |
달력의 시작값 (0) | 2019.10.03 |
댓글