Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ interface PinInterface {
fun getLocations(
@Path("userId") userId: Int,
): Call<PinResponse>

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.example.romanticyeojido.network.map

data class PinResponse(
val success: Boolean,
val locations: List<LocationData>
val result: List<LocationData>
)

data class LocationData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import retrofit2.http.Query
interface PopupInterface {
@GET("/api/v1/users/{userId}/map/memory") // 요청 경로
fun getPopupData(
@Header("Authorization") accessToken: String, // Authorization 헤더를 요청에 추가
@Header("Content-Type") contentType: String = "application/json",
@Path("userId") userId: Int,
@Query("latitude") latitude: String,
@Query("longitude") longitude: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.example.romanticyeojido.network.map

data class PopupResponse(
val success: Boolean,
val memory: MemoryData
val result: MemoryData
)

data class MemoryData(
Expand Down
150 changes: 128 additions & 22 deletions app/src/main/java/com/example/romanticyeojido/ui/map/MapActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.romanticyeojido.ui.map

import android.content.Context.MODE_PRIVATE
import android.content.Intent
import android.os.Bundle
import android.util.Log
Expand Down Expand Up @@ -60,7 +61,7 @@ class MapActivity: AppCompatActivity() {
sendNewPin(userId,latitude,longitude) // 서버에 핀 정보 전송

val intent = Intent(this, MemoryPostActivity::class.java).apply{}

onPause()
startActivity(intent)
clearUnsavedLabel() // 라벨 초기화
} ?: Toast.makeText(this, "핀을 선택해주세요!", Toast.LENGTH_SHORT).show()
Expand All @@ -71,20 +72,20 @@ class MapActivity: AppCompatActivity() {
}

// val locationId = intent.getIntExtra("locationId", 0)
// val title = intent.getStringExtra("title")
// val visit_date = intent.getStringExtra("visit_date")
// val content = intent.getStringExtra("content")
// val friends = intent.getStringExtra("friends")
// val summary = intent.getStringExtra("summary")

// Log.d("MapActivity", "받은 memory_data: $locationId, $title, $visit_date, $content, $friends, $summary")

initializeMap()
// val title = intent.getStringExtra("title")
// val visit_date = intent.getStringExtra("visit_date")
// val content = intent.getStringExtra("content")
// val friends = intent.getStringExtra("friends")
// val summary = intent.getStringExtra("summary")
//
// Log.d("MapActivity", "받은 추억 데이터: $title, $visit_date, $content, $friends, $summary")

initializeMap(userId)
fetchLocations(userId)
}

//API 호출 - 저장된 핀 호출
private fun fetchLocations(userId: Int) {
fun fetchLocations(userId: Int) {
val call = pinInterface.getLocations(userId)

call.enqueue(object : Callback<PinResponse> {
Expand All @@ -93,44 +94,59 @@ class MapActivity: AppCompatActivity() {
val pinResponse = response.body()
if (pinResponse != null && pinResponse.success) {
// locations가 null이 아닌지 확인
if (pinResponse.locations != null) {
pinResponse.locations.forEachIndexed { index, location ->
Log.d("Location", "위치 $index: 위도: ${location.latitude}, 경도: ${location.longitude}")

if (pinResponse.result != null) {
pinResponse.result.forEachIndexed { index, location ->
Log.d(
"Location",
"위치 $index: 위도: ${location.latitude}, 경도: ${location.longitude}"
)
if (location.latitude == null || location.longitude == null) {
Log.e("pinResponse", "위도/경도 값이 null입니다.")
}
val styles = kakaoMap?.labelManager?.addLabelStyles(
LabelStyles.from(
LabelStyle.from(R.drawable.ic_pin_gray).setAnchorPoint(0.5f, 1.0f)
try {
LabelStyle.from(R.drawable.ic_pin_gray)
.setAnchorPoint(0.5f, 1.0f)
} catch (e: Exception) {
Log.e("LabelStyleError", "LabelStyle 생성 중 오류 발생", e)
return // 오류 발생 시 실행 중단
}
)
)
if (styles == null) {
Log.e("pinResponse", "LabelStyles 생성 실패")
}
// 지도에 위치 추가
val options = LabelOptions.from(LatLng.from(location.latitude, location.longitude)).setStyles(styles)
val layer = kakaoMap?.labelManager?.layer

if (layer != null) {
val label = layer.addLabel(options)
label.show()
}
}
} else {
Log.d("API", "위치 정보가 없습니다.")
Log.d("pinResponse", "위치 정보가 없습니다.")
}
} else {
Log.d("API", "응답이 성공적이지 않음")
Log.d("pinResponse", "응답이 성공적이지 않음")
}
} else {
Log.e("API", "응답 실패: ${response.code()}")
Log.e("pinResponse", "응답 실패: ${response.code()}")
}
}

override fun onFailure(call: Call<PinResponse>, t: Throwable) {
Log.e("API", "API 호출 실패", t)
Log.e("pinResponse", "API 호출 실패", t)
}
})
}

private fun initializeMap() {
//지도 설정 함수
private fun initializeMap(userId: Int) {
binding.mapView.start(object : MapLifeCycleCallback() {
override fun onMapDestroy() {
Log.d("onMapDestroy", "onMapDestroy")
// 지도 API 종료 시 호출
}

Expand All @@ -141,6 +157,7 @@ class MapActivity: AppCompatActivity() {
override fun onMapReady(map: KakaoMap) {
kakaoMap = map
setupMap() // 지도 설정
fetchLocations(userId)
}

override fun getPosition(): LatLng {
Expand All @@ -154,9 +171,12 @@ class MapActivity: AppCompatActivity() {
override fun isVisible(): Boolean {
return true // 지도 표시 여부
}

})
}



// 지도 시작 설정
private fun setupMap() {
val position = LatLng.from(37.44983420181418,127.12727640486801)
Expand All @@ -173,6 +193,7 @@ class MapActivity: AppCompatActivity() {
private fun addLabel(position: LatLng) {
// 기존 임시 라벨 제거
unsavedLabel?.remove()

val styles = kakaoMap?.labelManager?.addLabelStyles(
LabelStyles.from(
LabelStyle.from(R.drawable.ic_pin).setAnchorPoint(0.5f, 1.0f)
Expand All @@ -183,8 +204,11 @@ class MapActivity: AppCompatActivity() {
val layer = kakaoMap?.labelManager?.layer

if (layer != null) {
// 새로운 라벨 추가
val label = layer.addLabel(options)
label.show()

// 라벨을 임시 라벨로 설정
unsavedLabel = label // 새로 생성된 라벨을 임시 라벨로 설정

latitude = label.position.latitude.toString()
Expand All @@ -194,15 +218,53 @@ class MapActivity: AppCompatActivity() {
binding.btnRegister.isEnabled = true
binding.btnRegister.setBackgroundColor(ContextCompat.getColor(this, R.color.P500))

// 핀 클릭 리스너
kakaoMap?.setOnLabelClickListener { map, labelLayer, clickedLabel ->
initLabelClickListener(map, labelLayer, clickedLabel)
true
}

// 위치 정보 저장
val spfLoc = getSharedPreferences("map_location", MODE_PRIVATE)
val editor = spfLoc.edit()
editor.putString("latitude", label.position.latitude.toString())
editor.putString("longitude", label.position.longitude.toString())
editor.apply()

// val spf = getSharedPreferences("MemoryContents", MODE_PRIVATE)
// val title = spf.getString("title", "")
// val visit_date = spf.getString("visit_date", "")
// val content = spf.getString("content", "")
// val friends = spf.getString("friends", "")
// val summary = spf.getString("summary", "")
//
// Log.d("MapActivity", "MemoryContents: $title")



// val styles = kakaoMap?.labelManager?.addLabelStyles(
// LabelStyles.from(
// try {
// LabelStyle.from(R.drawable.ic_pin_gray).setAnchorPoint(0.5f, 1.0f)
// } catch (e: Exception) {
// Log.e("LabelStyleError", "LabelStyle 생성 중 오류 발생", e)
// return // 오류 발생 시 실행 중단
// }
// )
// )
//
// if (styles == null) {
// Log.e("pinResponse", "LabelStyles 생성 실패")
// }
//
// // 지도에 위치 추가
// val options = LabelOptions.from(position).setStyles(styles)
// val layer = kakaoMap?.labelManager?.layer
//
// if (layer != null) {
// val fixedLabel = layer.addLabel(options)
// fixedLabel.show()
// }
}
}

Expand Down Expand Up @@ -264,10 +326,54 @@ class MapActivity: AppCompatActivity() {
override fun onResume() {
super.onResume()
binding.mapView.resume() // MapView resume
Log.d("MapLog", "Map_resume")

// 사용자 ID 가져오기
val spf = getSharedPreferences("UserPrefs", MODE_PRIVATE)
val userId = spf.getInt("USER_ID", 0)
Log.d("MapActivity", "USER_ID in MainActivity: $userId")

// 이전에 저장한 좌표
val spfLoc = getSharedPreferences("map_location", MODE_PRIVATE)
val latitude = spfLoc.getString("latitude", null)
val longitude = spfLoc.getString("longitude", null)

val memoryspf = getSharedPreferences("MemoryPrefs", MODE_PRIVATE)
val title = memoryspf.getString("title", "")
val visitDate = memoryspf.getString("visit_date", "")
val friends = memoryspf.getString("friends", "")
val content = memoryspf.getString("content", "")
val summary = memoryspf.getString("summary", "")

// 추억 데이터 로그 확인
Log.d("MapActivity", "추억 데이터: title=$title, visit_date=$visitDate, friends=$friends, content=$content, summary=$summary")

// 위치가 저장되어 있으면 그곳에 핀 고정
if (latitude != null && longitude != null) {
val position = LatLng.from(latitude.toDouble(), longitude.toDouble())
// 기존 핀 고정 (회색 핀으로)
val styles = kakaoMap?.labelManager?.addLabelStyles(
LabelStyles.from(
LabelStyle.from(R.drawable.ic_pin_gray).setAnchorPoint(0.5f, 1.0f)
)
)
val options = LabelOptions.from(position).setStyles(styles)
val layer = kakaoMap?.labelManager?.layer

if (layer != null) {
val fixedLabel = layer.addLabel(options)
fixedLabel.show()
}
}

// 위치 목록 가져오기
fetchLocations(userId)
}


override fun onPause() {
super.onPause()
binding.mapView.pause() // MapView pause
Log.d("MapLog", "Map_pause")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ class PopupActivity (private val context: Context) {
val apiService = RetrofitClient.instance.create(PopupInterface::class.java)
val accessToken = AccessTokenManager.getAccessToken() ?: ""

apiService.getPopupData(accessToken,"application/json",userId,latitude,longitude).enqueue(object : Callback<PopupResponse> {
apiService.getPopupData(userId,latitude,longitude).enqueue(object : Callback<PopupResponse> {
override fun onResponse(call: Call<PopupResponse>, response: Response<PopupResponse>) {
if (response.isSuccessful && response.body()?.success == true) {
response.body()?.memory?.let { memory ->
response.body()?.result?.let { result ->
// 성공 로그 추가
Log.d("PopupData", "데이터를 성공적으로 불러왔습니다: ${memory.title}, 방문일: ${memory.visit_date}, 친구: ${memory.friends}")
Log.d("PopupData", "데이터를 성공적으로 불러왔습니다: ${result.title}, 방문일: ${result.visit_date}, 친구: ${result.friends}")

binding.tvPopupTitle.text = memory.title
binding.tvPopupDate.text = "방문일: ${memory.visit_date} / 친구: ${memory.friends}"
binding.tvPopupDescription.text = memory.gpt_summary
binding.tvPopupTitle.text = result.title
binding.tvPopupDate.text = "방문일: ${result.visit_date} / 친구: ${result.friends}"
binding.tvPopupDescription.text = result.gpt_summary
Glide.with(binding.imgPopup.context)
.load(RetrofitClient.BASE_URL + memory.image_url)
.load(RetrofitClient.BASE_URL + result.image_url)
.into(binding.imgPopup)
}
} else {
Expand Down
Loading