안드로이드 구글맵 이상현상

조회수 1339회

안녕하세요. 안드로이드 공부하는 도중에 이상한 점을 해결 할 수 없어서 도움을 청합니다.

현재 구글맵을 Fragment로 만들어 띄우려고 합니다. 띄우는 대는 성공하였지만,

구글맵 로고, 마커만 표시될뿐 처음에는 지도에 관한건 뜨지 않습니다.

그러다 터치를 하게되면 한부분씩 구글맵이 늦게 나오기 시작하고, 줌,드래드 등등 해도 반응이 엄청나게 늦습니다.

이유를 알 수 있을까요?

2 답변

  • 좋아요

    1

    싫어요
    채택 취소하기

    MapView 의 경우 lite mode 가 아니면 Activity의 life cycle 을 반드시 notify 하여 사용해야 한다고 명시되어 있습니다. onResume(), onPause() 단계에서 맵 렌더링 스레드가 실행/중단 되는 것으로 알고 있는데 이는 복잡한 렌더링 요소들로 구성되는 맵의 특성상, life cycle 에 따른 렌더링 처리, 메모리 관리 등을 위한 것으로 보입니다.

    When using the API in fully interactive mode, users of the MapView class must forward all the activity life cycle methods to the corresponding methods in the MapView class. Examples of the life cycle methods include onCreate(), onDestroy(), onResume(), and onPause().

    https://developers.google.com/maps/documentation/android-sdk/lite

    • (•́ ✖ •̀)
      알 수 없는 사용자
    • 오늘도 하나 배워갑니다 :) 심승현 2018.7.26 17:14
  • 자답입니다! 대개 Fragment로 구글맵을 띄우는 방법은 구글링을 통하여 접하면,

    public class Google_map_fragment extends Fragment implements OnMapReadyCallback {
    
        private GoogleMap mMap;
        private MapView mapView = null;
        View layout;
    
        @Override
        public View onCreateView( LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
            Log.d("로그 : ","Google_map_fragment onCreateView");
    
            layout = inflater.inflate(R.layout.google_map_fragment,container,false);
            mapView = (MapView)layout.findViewById(R.id.map);
            mapView.getMapAsync(this);
            mapView.onCreate(savedInstanceState);
            return layout;
        }
    

    이런식의 코드를 보실수 있습니다.

    하지만 이렇게만 해놓고 실행하면 구글맵이 자연스럽게 실행되는 것이 아닌, 화면 터치를 계속해서 해야 한 부분씩 맵이 나오고 줌,아웃 같은 것도 잘 되지 않는 현상이 발생 합니다.

        @Override
        public void onResume() {
            mapView.onResume();
            super.onResume();
        }
        @Override
        public void onDestroy() {
            mapView.onDestroy();
            super.onDestroy();
        }
    
    

    이러한 경우 onResume , onDestroy 에 맵뷰.~~ 를 추가하여 해주시면 자연스럽게 돌아가는 구글맵을 사용 할 수 있습니다.

    이유는 잘 모르겠습니다. 자세한 이유를 아시는분 댓글좀 달아주세요!

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)