카카오내비 SDK와 관련된 질문과 답변을 올리는 카테고리입니다.
안녕하세요
질문 : 현재 자신의 위치를 표현하는 화살표가 실제 이동에 따라서 움직이지 않습니다. 왜 그런 것인지 잘 모르겠습니다.
startWithTrip() 메소드를 활용해서 간단하게 출발지에서 목적지까지 길안내를 하기위한 샘플앱을 제작하려고 합니다.
처음 NaviActivity에 접근하면 처음 현재 위치는 잘 보여집니다. 하지만 계속 움직여도 현재 위치를 표현해주는 화살표는 제자리입니다. GPS는 연결이 된 상태라고 생각합니다. “GPS가 연결되었습니다.” 라는 음성과 이동할때 어느 방향으로 가야하는지 음성안내가 나오기 때문입니다. 그리고 Taost 메세지로 현재 위치를 계속해서 확인해봐도 정수값이 수시로 바뀌는 것을 확인할 수 있습니다.
아래는 제가 작성한 코드입니다. 참고 부탁드리겠습니다.
사용한 knsdk_ui 버전 : “1.10.5”
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
class FindLoadApplication : Application() {
companion object {
lateinit var knsdk: KNSDK
}
override fun onCreate() {
super.onCreate()
initialize()
}
/**
* 길찾기 SDK의 초기화 및 파일이 저장될 경로를 설정합니다
*/
fun initialize() {
knsdk = KNSDK.apply {
// 파일 경로: data/data/com.kakaomobility.knsample/files/KNSample
install(this@FindLoadApplication, “$filesDir/KNSample”)
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.findloadsampleproject.databinding.ActivityNaviBinding
import com.kakaomobility.knsdk.KNCarFuel
import com.kakaomobility.knsdk.KNCarType
import com.kakaomobility.knsdk.KNCarUsage
import com.kakaomobility.knsdk.KNRouteAvoidOption
import com.kakaomobility.knsdk.KNRoutePriority
import com.kakaomobility.knsdk.KNSDK
import com.kakaomobility.knsdk.common.gps.WGS84ToKATEC
import com.kakaomobility.knsdk.common.objects.KNError
import com.kakaomobility.knsdk.common.objects.KNPOI
//import com.kakaomobility.knsdk.guidance.knguidance.KNDriveGuidance
import com.kakaomobility.knsdk.guidance.knguidance.KNGuidance
import com.kakaomobility.knsdk.guidance.knguidance.KNGuidance_CitsGuideDelegate
import com.kakaomobility.knsdk.guidance.knguidance.KNGuidance_GuideStateDelegate
import com.kakaomobility.knsdk.guidance.knguidance.KNGuidance_LocationGuideDelegate
import com.kakaomobility.knsdk.guidance.knguidance.KNGuidance_RouteGuideDelegate
import com.kakaomobility.knsdk.guidance.knguidance.KNGuideRouteChangeReason
import com.kakaomobility.knsdk.guidance.knguidance.KNGuidance_SafetyGuideDelegate
import com.kakaomobility.knsdk.guidance.knguidance.KNGuidance_VoiceGuideDelegate
import com.kakaomobility.knsdk.guidance.knguidance.citsguide.KNGuide_Cits
import com.kakaomobility.knsdk.guidance.knguidance.common.KNLocation
import com.kakaomobility.knsdk.guidance.knguidance.locationguide.KNGuide_Location
import com.kakaomobility.knsdk.guidance.knguidance.routeguide.KNGuide_Route
import com.kakaomobility.knsdk.guidance.knguidance.routeguide.objects.KNMultiRouteInfo
import com.kakaomobility.knsdk.guidance.knguidance.safetyguide.KNGuide_Safety
import com.kakaomobility.knsdk.guidance.knguidance.safetyguide.objects.KNSafety
import com.kakaomobility.knsdk.guidance.knguidance.voiceguide.KNGuide_Voice
import com.kakaomobility.knsdk.trip.knrouteconfiguration.KNRouteConfiguration
import com.kakaomobility.knsdk.trip.kntrip.KNTrip
import com.kakaomobility.knsdk.trip.kntrip.knroute.KNRoute
import okhttp3.logging.HttpLoggingInterceptor.Logger
class NaviActivity : AppCompatActivity(), KNGuidance_LocationGuideDelegate,
KNGuidance_GuideStateDelegate, KNGuidance_SafetyGuideDelegate, KNGuidance_RouteGuideDelegate,
KNGuidance_CitsGuideDelegate, KNGuidance_VoiceGuideDelegate {
val TAG = “NaviActivity”
private lateinit var binding : ActivityNaviBinding
//private lateinit var guidance: KNDriveGuidance
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityNaviBinding.inflate(layoutInflater)
setContentView(binding.root)
// status bar 영역까지 사용하기 위한 옵션
window?.apply {
statusBarColor = Color.TRANSPARENT
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
requestRoute3()
}
fun requestRoute3() {
val goalKatec = WGS84ToKATEC(126.972263, 37.556091)
val startKatec = WGS84ToKATEC(127.102308, 37.334522)
// 출발지와 목적지를 설정합니다.
val startPoi = KNPOI("현위치", startKatec.x.toInt(),startKatec.y.toInt(),"현위치")
val goalPoi = KNPOI("목적지",goalKatec.x.toInt(),goalKatec.y.toInt(),"목적지")
FindLoadApplication.knsdk.makeTripWithStart(
aStart = startPoi,
aGoal = goalPoi,
aVias = null
) { aError, aTrip ->
// 경로 요청이 성공하면 aError는 Null이 됩니다.
if (aError == null) {
Log.v(TAG, "경로요청 성공")
runOnUiThread {
binding.naviView.guidance = FindLoadApplication.knsdk.sharedGuidance()!!
FindLoadApplication.knsdk.sharedGuidance()?.apply {
guideStateDelegate = this@NaviActivity
locationGuideDelegate = this@NaviActivity
routeGuideDelegate = this@NaviActivity
safetyGuideDelegate = this@NaviActivity
citsGuideDelegate = this@NaviActivity
voiceGuideDelegate = this@NaviActivity
FindLoadApplication.knsdk.sharedGuidance()?.startWithTrip(aTrip, KNRoutePriority.KNRoutePriority_Time, KNRouteAvoidOption.KNRouteAvoidOption_RoadEvent.value)
}
}
}
}
}
override fun guidanceDidUpdateLocation(
aGuidance: KNGuidance,
aLocationGuide: KNGuide_Location
) {
// pos 경로 내 위치 좌표(카텍(KATEC) 좌표계 사용)
Toast.makeText(this, "x : ${aLocationGuide.location?.pos?.x?.toInt().toString()} y : ${aLocationGuide.location?.pos?.y?.toInt().toString()}",Toast.LENGTH_SHORT).show()
binding.naviView.guidanceDidUpdateLocation(aGuidance, aLocationGuide)
}
override fun guidanceCheckingRouteChange(aGuidance: KNGuidance) {
binding.naviView.guidanceCheckingRouteChange(aGuidance)
}
override fun guidanceDidUpdateIndoorRoute(aGuidance: KNGuidance, aRoute: KNRoute?) {
binding.naviView.guidanceDidUpdateIndoorRoute(aGuidance, aRoute)
}
override fun guidanceDidUpdateRoutes(
aGuidance: KNGuidance,
aRoutes: List<KNRoute>,
aMultiRouteInfo: KNMultiRouteInfo?
) {
binding.naviView.guidanceDidUpdateRoutes(aGuidance, aRoutes, aMultiRouteInfo)
}
override fun guidanceGuideEnded(aGuidance: KNGuidance) {
binding.naviView.guidanceGuideEnded(aGuidance)
}
override fun guidanceGuideStarted(aGuidance: KNGuidance) {
binding.naviView.guidanceGuideStarted(aGuidance)
}
override fun guidanceOutOfRoute(aGuidance: KNGuidance) {
binding.naviView.guidanceOutOfRoute(aGuidance)
}
override fun guidanceRouteChanged(
aGuidance: KNGuidance,
aFromRoute: KNRoute,
aFromLocation: KNLocation,
aToRoute: KNRoute,
aToLocation: KNLocation,
aChangeReason: KNGuideRouteChangeReason
) {
binding.naviView.guidanceRouteChanged(aGuidance)
}
override fun guidanceRouteUnchanged(aGuidance: KNGuidance) {
binding.naviView.guidanceRouteUnchanged(aGuidance)
}
override fun guidanceRouteUnchangedWithError(aGuidnace: KNGuidance, aError: KNError) {
binding.naviView.guidanceRouteUnchangedWithError(aGuidnace, aError)
}
// check point
override fun guidanceDidUpdateAroundSafeties(
aGuidance: KNGuidance,
aSafeties: List<KNSafety>?
) {
binding.naviView.guidanceDidUpdateAroundSafeties(aGuidance, aSafeties)
}
// check point
override fun guidanceDidUpdateSafetyGuide(
aGuidance: KNGuidance,
aSafetyGuide: KNGuide_Safety?
) {
binding.naviView.guidanceDidUpdateSafetyGuide(aGuidance, aSafetyGuide)
}
override fun guidanceDidUpdateRouteGuide(aGuidance: KNGuidance, aRouteGuide: KNGuide_Route) {
binding.naviView.guidanceDidUpdateRouteGuide(aGuidance, aRouteGuide)
}
override fun didUpdateCitsGuide(aGuidance: KNGuidance, aCitsGuide: KNGuide_Cits) {
binding.naviView.didUpdateCitsGuide(aGuidance, aCitsGuide)
}
override fun didFinishPlayVoiceGuide(aGuidance: KNGuidance, aVoiceGuide: KNGuide_Voice) {
binding.naviView.didFinishPlayVoiceGuide(aGuidance, aVoiceGuide)
}
override fun shouldPlayVoiceGuide(
aGuidance: KNGuidance,
aVoiceGuide: KNGuide_Voice,
aNewData: MutableList<ByteArray>
): Boolean {
return binding.naviView.shouldPlayVoiceGuide(aGuidance, aVoiceGuide, aNewData)
}
override fun willPlayVoiceGuide(aGuidance: KNGuidance, aVoiceGuide: KNGuide_Voice) {
binding.naviView.willPlayVoiceGuide(aGuidance, aVoiceGuide)
}
}