카카오맵 api를 활용해서
원하는 좌표상 위치를 지도의 중심점으로 설정하고
마커를 표시하자
** 이 글은 아래 글과 이어진다. 카카오맵 사용 시작부터 알고 싶다면 아래 링크 참고
https://onedaythreecoding.tistory.com/7
[Android/Kotlin] 카카오맵 KakaoMap API 시작하기 : MapView, 초기설정
카카오맵으로 안드로이드 앱에 지도 띄우기 카카오 공식 문서만 보고 해보려다가 처음 해보는 사람 입장에서는 모르는 부분들이 꽤나 있어 도움이 되고자 글쓴다. 결과물 1. SDK파일 다운로드 카
onedaythreecoding.tistory.com
결과물


activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="안드로이드 카카오맵 API 활용 : \nMapView 띄우기"
android:textColor="#822FD5"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/clKakaoMapView"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt
package com.example.kakaomaptestapp
import android.content.pm.PackageManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Base64
import android.util.Log
import com.example.kakaomaptestapp.databinding.ActivityMainBinding
import net.daum.mf.map.api.MapPOIItem
import net.daum.mf.map.api.MapPoint
import net.daum.mf.map.api.MapView
import java.security.MessageDigest
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
val mapView = MapView(this)
binding.clKakaoMapView.addView(mapView)
//수원 화성의 위도, 경도
val mapPoint = MapPoint.mapPointWithGeoCoord(37.28730797086605, 127.01192716921177)
//지도의 중심점을 수원 화성으로 설정, 확대 레벨 설정 (값이 작을수록 더 확대됨)
mapView.setMapCenterPoint(mapPoint, true)
mapView.setZoomLevel(1, true)
//마커 생성
val marker = MapPOIItem()
marker.itemName = "이곳이 수원 화성입니다"
marker.mapPoint = mapPoint
marker.markerType = MapPOIItem.MarkerType.BluePin
marker.selectedMarkerType = MapPOIItem.MarkerType.RedPin
mapView.addPOIItem(marker)
}
}
마커를 탭하면 BluePin이 아닌 RedPin으로 markerStyle이 바뀌도록 했다.
itemName은 마커 탭 시 보이는 말풍선에 들어갈 내용이다.
결과


마커랑 말풍선 크기가 너무 작아서 커스텀이 필요할 것 같다.
순탄하게 성공~
공식문서가 한글로 되어있으니까 너무 좋다..
영어 잘하는 사람들은 구글링할 때 이렇게 수월한 것인가
부럽다
영어공부해야지
'Android > API' 카테고리의 다른 글
[KakaoLogin] 카카오 계정 연동 로그인 구현하기 (Kotlin) (0) | 2022.03.03 |
---|---|
메모) Android Api 서버 통신 Retrofit 활용하기 (0) | 2021.08.08 |
<ERROR> Expected BEGIN_OBJECT but was STRING at line 1 column 79 path : OkHttpClient의 HttpLoggingInterceptor, Retrofit (0) | 2021.08.04 |
[Android/Kotlin] 카카오맵 KakaoMap API 시작하기 : MapView, 초기설정 (2) | 2021.07.23 |
카카오맵 api를 활용해서
원하는 좌표상 위치를 지도의 중심점으로 설정하고
마커를 표시하자
** 이 글은 아래 글과 이어진다. 카카오맵 사용 시작부터 알고 싶다면 아래 링크 참고
https://onedaythreecoding.tistory.com/7
[Android/Kotlin] 카카오맵 KakaoMap API 시작하기 : MapView, 초기설정
카카오맵으로 안드로이드 앱에 지도 띄우기 카카오 공식 문서만 보고 해보려다가 처음 해보는 사람 입장에서는 모르는 부분들이 꽤나 있어 도움이 되고자 글쓴다. 결과물 1. SDK파일 다운로드 카
onedaythreecoding.tistory.com
결과물


activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="안드로이드 카카오맵 API 활용 : \nMapView 띄우기"
android:textColor="#822FD5"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/clKakaoMapView"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt
package com.example.kakaomaptestapp
import android.content.pm.PackageManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Base64
import android.util.Log
import com.example.kakaomaptestapp.databinding.ActivityMainBinding
import net.daum.mf.map.api.MapPOIItem
import net.daum.mf.map.api.MapPoint
import net.daum.mf.map.api.MapView
import java.security.MessageDigest
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
val mapView = MapView(this)
binding.clKakaoMapView.addView(mapView)
//수원 화성의 위도, 경도
val mapPoint = MapPoint.mapPointWithGeoCoord(37.28730797086605, 127.01192716921177)
//지도의 중심점을 수원 화성으로 설정, 확대 레벨 설정 (값이 작을수록 더 확대됨)
mapView.setMapCenterPoint(mapPoint, true)
mapView.setZoomLevel(1, true)
//마커 생성
val marker = MapPOIItem()
marker.itemName = "이곳이 수원 화성입니다"
marker.mapPoint = mapPoint
marker.markerType = MapPOIItem.MarkerType.BluePin
marker.selectedMarkerType = MapPOIItem.MarkerType.RedPin
mapView.addPOIItem(marker)
}
}
마커를 탭하면 BluePin이 아닌 RedPin으로 markerStyle이 바뀌도록 했다.
itemName은 마커 탭 시 보이는 말풍선에 들어갈 내용이다.
결과


마커랑 말풍선 크기가 너무 작아서 커스텀이 필요할 것 같다.
순탄하게 성공~
공식문서가 한글로 되어있으니까 너무 좋다..
영어 잘하는 사람들은 구글링할 때 이렇게 수월한 것인가
부럽다
영어공부해야지
'Android > API' 카테고리의 다른 글
[KakaoLogin] 카카오 계정 연동 로그인 구현하기 (Kotlin) (0) | 2022.03.03 |
---|---|
메모) Android Api 서버 통신 Retrofit 활용하기 (0) | 2021.08.08 |
<ERROR> Expected BEGIN_OBJECT but was STRING at line 1 column 79 path : OkHttpClient의 HttpLoggingInterceptor, Retrofit (0) | 2021.08.04 |
[Android/Kotlin] 카카오맵 KakaoMap API 시작하기 : MapView, 초기설정 (2) | 2021.07.23 |