[FEAT] 카카오 맵 기본 사용환경 구성#58
Conversation
| val response = mapService.getMapDetail( | ||
| mapId = mapId | ||
| ).handleBaseResponse().getOrThrow() | ||
| } |
There was a problem hiding this comment.
runCatching 자체가 블록의 마지막 구문을 반환하는 거여서,
response 라는 변수를 생성해서 할당하지 않아도 정상적으로 원하는 값이 반환이 될 것 같아요.
suspend fun getMapDetail(
mapId: Int
) = runCatching {
mapService.getMapDetail(mapId = mapId).handleBaseResponse().getOrThrow()
}| @Serializable | ||
| data class MapDetailResponse( | ||
| @SerialName("menuId") | ||
| val menuId: Int, |
There was a problem hiding this comment.
Api 명세서 상에는 기술되어 있지 않지만 Swagger 상 $Int64 으로 되어있는 거를 Long 타입이라도 답변 받았습니다!
그래서 Id 관련 및 $Int64 로 되어있는 필드에는 Long 타입으로 변경해야 할 것 같아요.
ikseong00
left a comment
There was a problem hiding this comment.
좋습니당.
viewModelScope 가 필요한 지 ,
LaunchedEffect 에서 기본 CoroutineScope 인지 , rememberCoroutineScope() 를 사용해야 하는 상황인 지 확인해주시면 감사하겠습니다.
| } | ||
|
|
||
| @Composable | ||
| fun MapViewWithLifecycle( |
| import kotlinx.coroutines.flow.StateFlow | ||
|
|
||
| class MapController { | ||
| val _kakaoMap = MutableStateFlow<KakaoMap?>(null) |
| fun moveCamera(latitude: Double, longitude: Double) { | ||
| viewModelScope.launch { | ||
| mapController.kakaoMap.value?.let { map -> | ||
| val cameraUpdate = CameraUpdateFactory.newCenterPosition(LatLng.from(latitude, longitude)) | ||
| map.moveCamera(cameraUpdate) | ||
| updateCurrentCenter() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // 지도 중앙 좌표 업데이트 | ||
| fun updateCurrentCenter() { | ||
| viewModelScope.launch { | ||
| mapController.kakaoMap.value?.let { map -> | ||
| val center = map.cameraPosition?.position | ||
| _currentCenter.value = center | ||
| if (center != null) { | ||
| Log.d("SearchMenuViewModel", "현재 지도 중심 좌표: ${center.latitude}, ${center.longitude}") | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
이 부분에서 viewModelScope 를 쓰지 않아도 될 것 같습니다.
- kakaMap 이라는 Flow 를 collect 하지 않고 , 그 시점에서의 값만 사용.
- cameraPosition 을 이동하는 함수는 suspend 함수가 아님.
| // 지도에 핀 추가 | ||
| fun addMarker(latitude: Double, longitude: Double, resourceId: Int) { | ||
| viewModelScope.launch { | ||
| mapController.kakaoMap.value?.let { map -> | ||
| val style = map.labelManager?.addLabelStyles( | ||
| LabelStyles.from(LabelStyle.from(resourceId)) | ||
| ) | ||
| val options = LabelOptions.from(LatLng.from(latitude, longitude)).setStyles(style) | ||
| map.labelManager?.layer?.addLabel(options) | ||
| map.setOnLabelClickListener { kakaoMap, labelLayer, label -> | ||
| // TODO: 핀 클릭시 동작 정의 | ||
| Log.d("SearchMenuViewModel", "핀 클릭됨") | ||
| moveCamera(latitude = label.position.latitude, longitude = label.position.longitude) | ||
| true | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // 지도의 전체 핀 제거 | ||
| fun clearMarkers() { | ||
| viewModelScope.launch { | ||
| mapController.kakaoMap.value?.let { map -> | ||
| map.labelManager?.layer?.removeAll() | ||
| } | ||
| } | ||
| } |
| // 지도에 검색 결과 핀 추가 | ||
| fun showSearchResultOnMap() { | ||
| viewModelScope.launch { | ||
| clearMarkers() | ||
| searchResult.value?.forEach { store -> | ||
| val latitude = store.storeMapY | ||
| val longitude = store.storeMapX | ||
| addMarker(latitude, longitude, R.drawable.img_popup_dice) | ||
| Log.d("SearchMenuViewModel", "마커 추가: ${store.storeTitle} lat: (${latitude}, long: ${longitude})") | ||
| } | ||
| // 첫 번째 검색 결과로 카메라 이동 | ||
| searchResult.value?.get(0)?.let { moveCamera(it.storeMapY, it.storeMapX) } | ||
| } | ||
| } | ||
| } |
| launch { | ||
| viewModel.getCrawlingHistory() | ||
| } |
There was a problem hiding this comment.
rememberCoroutineScope() 없이 그냥 기본값의 CoroutineScope 를 선언하면 해당 key 값이 변경될 때 마다
내부의 코루틴 Job 이 삭제되고 새로운 코루틴이 생성될 것 같습니다. (getCrawlingHistory() 함수가 key 값 변경에 따라
getCrawlingHistory()실행 중searchBarFocused가 변하는 경우
rememberCoroutineScope()사용 시 -> 그대로 유지됨.- 사용 X -> 코루틴이 취소되고 다시 새로운
getCrawlingHistory()를 실행하는 코루틴이 생성됨.
혹시 위 코드 구현 시 2번을 염두하고 구현을 하신 걸까요 ??
There was a problem hiding this comment.
아직 세부작업까지는 진행하지 않아서 놓친 것 같습니다. 반영해서 수정 후 merge하도록 하겠습니다

🚀 이슈번호
✏️ 변경사항
<5/15 기준 업데이트된 부분들>
📷 스크린샷
SearchMenuScreen
Screen_Recording_20250515_072235_OurMenu.mp4
✍️ 사용법
🎸 기타