반응형
네이버 v3 지도에 경로 그리기.
초기 설정은 네이버 api 참조.
PathOverlay와 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 | //전역 변수 private ArrayList<GPSLocation> arrGpsLocation; private List<LatLng> lstLatLng; //최초 조회된 좌표, 우후 추가 된 부분만 조회할 경우 구분하기위해서 필요함. private static NaverMap nMap; private static PathOverlay path; //단일 경로 private MultipartPathOverlay multipartPath; //다중경로 //전역 변수 public void MapDraw() { path = new PathOverlay(); //ArrowheadPathOverlay int nCnt = 0 ; int moveDistance = 0 ; Marker marker; lstLatLng= new ArrayList<>(); LatLng temp = new LatLng( 0 , 0 ); for ( int i = 1 ; i < arrGpsLocation.size(); i++) { // for문 안에는 기초 데이터 생성임. 중요한 부분은 아님. temp = new LatLng(arrGpsLocation.get(i).getLatitude(), arrGpsLocation.get(i).getLongitude()); lstLatLng.add(temp); moveDistance += arrGpsLocation.get(i).getDistance(); if (nCnt == 200 ) //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(arrGpsLocation.get(i).getPositionTime()); marker.setCaptionRequestedWidth( 200 ); marker.setCaptionTextSize( 10 ); marker.setSubCaptionText(String.valueOf(moveDistance) + "M" ); marker.setSubCaptionColor(Color.BLUE); marker.setSubCaptionTextSize( 10 ); marker.setMap(nMap); nCnt = 0 ; moveDistance = 0 ; } nCnt++; } if (multipartPath != null ) //다중 경로를 사용하지 않는 다면 필요 없음. multipartPath.setMap( null ); path.setCoords(lstLatLng); //좌표 넣기 path.setColor(Color.RED); //생상 path.setHideCollidedSymbols( false ); //심볼을 보여줄지 표시 //path.setHideCollidedMarkers(true);//마커를 안보이게 설정. 보여야 되므로 주석 path.setMap(nMap); //맵연결 CameraPosition nCameraPosition = new CameraPosition(temp, 15 ); //카메라 좌표와 zoom 상태 nMap.setCameraPosition(nCameraPosition); //카메라 위치 이동 } |
ㄴㅇㄹㄴㅇㄹㄴㅇㄹ
반응형
'Android' 카테고리의 다른 글
안드로이드 해시키 코드로 조회 (0) | 2019.10.20 |
---|---|
네이버 플랫폼 맵 MultipartPathOverlay활용. 다중 경로 그리기 (0) | 2019.10.11 |
androidx.appcompat.widget.toolbar vs android.support.v7.widget.toolbar (0) | 2019.10.05 |
달력의 시작값 (0) | 2019.10.03 |
error: cannot resolve constructor (0) | 2019.10.01 |
댓글