Naver Map Api 사용해서 지도 기능 구현해보기
build.gradle(:app)
implementation 'com.naver.maps:map-sdk:3.16.2'
implementation("com.google.android.gms:play-services-location:16.0.0")
build.gradle(project)
buildscript {
repositories {
google()
mavenCentral()
maven {
url 'https://naver.jfrog.io/artifactory/maven/'
}
}
}
settings.gradle(project)
repositories {
google()
mavenCentral()
maven {
url 'https://naver.jfrog.io/artifactory/maven/'
}
}
api_key
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="naver_map_api_key">여기에 붙여넣기</string>
</resources>
AndroidManifest.xml
<meta-data
android:name="com.naver.maps.map.CLIENT_ID"
android:value="@string/naver_map_api_key"/>
activity_map.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.naver.maps.map.MapView
android:id="@+id/naverMap"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<com.naver.maps.map.widget.LocationButtonView
android:id="@+id/currentLocationButton"
android:layout_width="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="60dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="wrap_content" />
</androidx.constraintlayout.widget.ConstraintLayout>
MapActivity.kt
class MapActivity: AppCompatActivity(), OnMapReadyCallback, Overlay.OnClickListener{
private var naverMap: NaverMap? = null
lateinit var binding: ActivityMapBinding
private val markerClickListener = object : Overlay.OnClickListener{
override fun onClick(overlay: Overlay): Boolean {
return false
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMapBinding.inflate(layoutInflater)
setContentView(binding.root)
mapView.onCreate(savedInstanceState)
mapView.getMapAsync(this)
}
override fun onMapReady(map: NaverMap){
naverMap = map
}
override fun onClick(p0: Overlay): Boolean {
return markerClickListener.onClick(p0)
}
}