<meta-data
android:name="com.naver.maps.map.CLIENT_ID"
android:value="ootzd3244r" />
//Naver Map
implementation("com.naver.maps:map-sdk:3.17.0")
implementation("com.google.android.gms:play-services-location:17.0.0")
class RecordDetailMapFragment : Fragment(), OnMapReadyCallback {
private lateinit var naverMap: NaverMap
private lateinit var mapView: MapView
...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// mapView ๋ณ์ ์ด๊ธฐํ
mapView = binding.mvRecordDetailFullMap
mapView.onCreate(savedInstanceState)
mapView.getMapAsync(this)
}
override fun onMapReady(naverMap: NaverMap) {
// ๋ง์ปค ๊ฐ์ฒด ์์ฑ
val marker = Marker()
// ๋ง์ปค ์์น ์ค์ (์: ์์ธ ์์ฒญ)
marker.position = LatLng(37.5663, 126.9779)
// ๋ง์ปค ํ์ดํ ์ค์ (์ ํ ์ฌํญ)
marker.captionText = "์์ธ ์์ฒญ"
// ๋ง์ปค ์์ด์ฝ ์ค์ (์ ํ ์ฌํญ)
marker.icon = OverlayImage.fromResource(R.drawable.marker_icon)
// ๋ง์ปค ์ง๋์ ์ถ๊ฐ
marker.map = naverMap
// ์นด๋ฉ๋ผ ์์น์ ์ค ๋ ๋ฒจ ์กฐ์ (์ ํ ์ฌํญ)
val cameraUpdate = CameraUpdate.scrollTo(marker.position).animate(CameraAnimation.Easing)
naverMap.moveCamera(cameraUpdate)
naverMap.moveCamera(CameraUpdate.zoomTo(10.0))
}
๋งต๋ทฐ๊ฐ ์๋๋ก์ด๋์ ์๋ช
์ฃผ๊ธฐ ์ด๋ฒคํธ์ ๋ง์ถฐ ์ ์ ํ๊ฒ ๋์ํ ์ ์๋๋ก ํ๊ธฐ ์ํด ๋งต๋ทฐ(MapView)์ ์๋ช
์ฃผ๊ธฐ ๋ฉ์๋๋ฅผ ํ๋๊ทธ๋จผํธ๋ ์กํฐ๋นํฐ์ ์๋ช
์ฃผ๊ธฐ ๋ฉ์๋ ๋ด์์ ํธ์ถํ๋ ๊ฒ์ด ์ค์ํ๋ค.
๋ฐ๋ผ์ ๋งต๋ทฐ์ onCreate, onResume, onPause, onDestroy, onLowMemory, onStart, onStop ๋ฑ์ ๋ฉ์๋๋ฅผ ๊ฐ๊ฐ ํ๋๊ทธ๋จผํธ๋ ์กํฐ๋นํฐ์ ๋์ผํ ์๋ช
์ฃผ๊ธฐ ๋ฉ์๋ ๋ด์์ ํธ์ถํ์ฌ, ๋งต๋ทฐ๊ฐ ์๋๋ก์ด๋ ์๋ช
์ฃผ๊ธฐ ์ด๋ฒคํธ์ ๋ง์ถฐ ์ฌ๋ฐ๋ฅด๊ฒ ๋์ํ๊ณ ์์์ ํจ์จ์ ์ผ๋ก ๊ด๋ฆฌํ ์ ์๋๋ก ํด์ผ ํ๋ค.
override fun onStart() {
super.onStart()
mapView.onStart()
}
override fun onResume() {
super.onResume()
mapView.onResume()
}
override fun onPause() {
mapView.onPause()
super.onPause()
}
override fun onStop() {
mapView.onStop()
super.onStop()
}
override fun onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}
override fun onDestroyView() {
super.onDestroyView()
mapView.onDestroy()
_binding = null
}
markers.forEach { marker ->
marker.captionText = "์ฅ์ ์ด๋ฆ" // ์ค์ ์ฅ์ ์ด๋ฆ์ผ๋ก ๋์ฒดํด์ผ ํฉ๋๋ค.
marker.setCaptionAligns(Align.Bottom)
marker.captionColor = Color.BLACK
marker.captionHaloColor = Color.WHITE
marker.captionTextSize = 16f
}
if (zoom > 14.0) {
// ํ๋ ๋ ๋ฒจ์ด ์๊ณ๊ฐ ์ด์์ผ ๋ ๋ง์ปค ์บก์
๋ณด์ด๊ธฐ
markers.forEach { marker ->
marker.captionText = "์ฅ์ ์ด๋ฆ"
marker.setCaptionAligns(Align.Bottom)
marker.captionColor = Color.BLACK
marker.captionHaloColor = Color.WHITE
marker.captionTextSize = 16f
}
} else {
// ํ๋ ๋ ๋ฒจ์ด ์๊ณ๊ฐ ๋ฏธ๋ง์ผ ๋ ๋ง์ปค ์บก์
์จ๊ธฐ๊ธฐ
markers.forEach { marker ->
marker.captionText = ""
}
}
naverMap.uiSettings.isZoomControlEnabled = false