넵 api 통해서 얻은 좌표값을 바로 넣어서 했고 디버그로 좌표만 빼서 직접 넣었는데도 잘못된 좌표처럼 바다쪽으로 이동을 합니다.
// 키워드 검색 함수
private fun searchKeyword(keyword: String) {
val retrofit = Retrofit.Builder() // Retrofit 구성
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
val api = retrofit.create(KakaoAPI::class.java) // 통신 인터페이스를 객체로 생성
val call = api.getSearchKeyword(API_KEY, keyword) // 검색 조건 입력
// API 서버에 요청
call.enqueue(object : Callback<LocationResult> {
override fun onResponse(
call: Call<LocationResult>,
response: Response<LocationResult>
) {
if (response.isSuccessful) {
if (response.body() != null) {
adapter.setData(
this@CustomInformAddressActivity, viewModel,
response.body()!!.getDocuments()!!
)
}
}
}
override fun onFailure(call: Call<LocationResult>, t: Throwable) {
// 통신 실패
Log.w("MainActivity", "통신 실패: ${t.message}")
}
})
}
//interface
interface KakaoAPI {
@GET(“v2/local/search/keyword.json”) // Keyword.json의 정보를 받아옴
fun getSearchKeyword(
@Header(“Authorization”) key: String, // 카카오 API 인증키 [필수]
@Query(“query”) query: String // 검색을 원하는 질의어 [필수]
): Call<LocationResult> // 받아온 정보가 ResultSearchKeyword 클래스의 구조로 담김
}
//model
class LocationResult {
@SerializedName("documents")
@Expose
private var documents: MutableList<LocationDocument>? = null
fun getDocuments(): MutableList<LocationDocument>? {
return documents
}
fun setDocuments(documents: MutableList<LocationDocument>?) {
this.documents = documents
}
}
//값 받아서 이동하는 함수
viewModel.intentReLocationView.observe(this, Observer {
Handler().postDelayed(Runnable { setLocation(it.getString(“x”, lat.toString())!!.toDouble(), it.getString(“y”,
lng.toString()
)!!.toDouble()) }, 200L)
})
fun setLocation(lat: Double, lng: Double){
binding.editAddressDetail.requestFocus()
val marker = MapPOIItem()
marker.apply {
itemName = “test”
mapPoint = MapPoint.mapPointWithGeoCoord(lat, lng) // 좌표
markerType = MapPOIItem.MarkerType.CustomImage // 마커 모양 (커스텀)
customImageResourceId = R.drawable.ico_custom_marker // 커스텀 마커 이미지
selectedMarkerType = MapPOIItem.MarkerType.CustomImage // 클릭 시 마커 모양 (커스텀)
isCustomImageAutoscale = false // 커스텀 마커 이미지 크기 자동 조정
setCustomImageAnchor(0.5f, 1.0f) // 마커 이미지 기준점
}
mapView.removeAllPOIItems()
mapView.setMapCenterPoint(MapPoint.mapPointWithGeoCoord(lat, lng), true);
mapView.addPOIItem(marker)
}
이 함수들 실행전에는 현재위치에서 맵이 실행되게 해놓은 상태입니다.
실제 사용되는 좌표들을 입력하면 이동을 잘하는데 api 통해서 받은 좌표들은 다 안되는거같습니다.