johyunchol / kakao_map_plugin

MIT License
27 stars 18 forks source link

마커에 대한 질문입니다. #27

Closed duckey-kim closed 6 months ago

duckey-kim commented 8 months ago

안녕하세요 0.2.4 버전을 사용하고 있습니다. 선택한 차량의 현재위치를 마커로 표시해주는 것을 진행하고 있는데요 다른 차량을 선택할 시에 지도의 중앙이 움직이면서 차량의 위치에 옮겨지는거 같은데, 마커는 바로 생성이 안되드라구요.

도움을 받거나 제가 봐야하는 문서가 있을까요 ?

카카오맵이 그려지는 부분

SizedBox(
                  height: height * 0.9,
                  width: width,
                  child: KakaoMap(
                    center: LatLng(status.latitude, status.longitude),
                    onMapCreated: ((controller) {
                      mapController.kakaoMapController = controller;
                    }),
                    zoomControl: true,
                    zoomControlPosition: ControlPosition.right,
                  ),
                ),

차량 선택시 마커 그리는 부분(한개의 마커만 그리기 위해 markerId 통일)

kakaoMapController?.addMarker(
              markers: [Marker(markerId: "location", latLng: LatLng(vehicleStatus.latitude, vehicleStatus.longitude))]);
          kakaoMapController?.panTo(LatLng(vehicleStatus.latitude, vehicleStatus.longitude));
johyunchol commented 8 months ago

네 안녕하세요.

마커를 사용하기 위해서는

KakaoMap(
        onMapCreated: ((controller) async {
          mapController = controller;

          markers.add(Marker(
            markerId: UniqueKey().toString(),
            latLng: await mapController.getCenter(),
          ));

          setState(() {});
        }),
        markers: markers.toList(),
        center: LatLng(37.3608681, 126.9306506),
      )

위 예시에서와 같이 KakaoMap 위젯의 markers attribute 에 markers array 를 넘겨주어야 합니다.

@duckey-kim 님께서 작성하신대로라면 markers 의 state 변경을 감지 하지 못해 마커를 그리지못한 것으로 보이구요. panTo 함수는 state 변경과는 상관없이 함수가 호출되면 이동하게 됩니다.

https://github.com/johyunchol/kakao_map_plugin/blob/main/example/lib/src/overlay_1_marker_screen.dart

여기에 전체 에제가 있으니 확인 해 보시면 됩니다!