Skip to content

Commit df451b1

Browse files
authored
feat: 네이버 지도 SDK 세팅 (#1)
* feat: 네이버 맵 세팅 * chore: gitignore 파일 수정 * feat: 네이버 맵 기본 로직 구현(위치 조회, 카메라 이동) * chore: 카카오맵 관련 코드 제거
1 parent 376fe9f commit df451b1

File tree

14 files changed

+168
-116
lines changed

14 files changed

+168
-116
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.iml
22
.gradle
33
/local.properties
4+
/.idea
45
/.idea/caches
56
/.idea/libraries
67
/.idea/modules.xml

app/build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ android {
2323
buildTypes {
2424
debug {
2525
applicationIdSuffix ".debug"
26-
resValue "string", "KAKAO_KEY", localProperties['KAKAO_KEY_DEV']
26+
resValue "string", "NAVER_CLIENT_ID", localProperties['NAVER_CLIENT_ID']
2727
}
2828
release {
2929
minifyEnabled false
@@ -41,14 +41,19 @@ android {
4141

4242
dependencies {
4343

44-
implementation 'androidx.core:core-ktx:1.7.0'
44+
implementation 'androidx.core:core-ktx:1.10.0'
4545
implementation 'androidx.appcompat:appcompat:1.6.1'
46+
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01'
4647
implementation 'com.google.android.material:material:1.8.0'
4748
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
4849
implementation fileTree(dir: 'src/main/jniLibs', include: ['*.aar', '*.jar'], exclude: [])
4950
testImplementation 'junit:junit:4.13.2'
5051
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
5152
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
5253

53-
implementation files('libs/libDaumMapAndroid.jar')
54+
// 지도 관련 라이브러리
55+
implementation('com.naver.maps:map-sdk:3.16.2') {
56+
exclude group: 'com.android.support'
57+
}
58+
implementation 'com.google.android.gms:play-services-location:16.0.0'
5459
}

app/libs/libDaumMapAndroid.jar

-333 KB
Binary file not shown.

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
android:theme="@style/Theme.MenuMeonya"
1818
android:usesCleartextTraffic="true"
1919
tools:targetApi="31">
20+
<activity
21+
android:name=".NaverActivity"
22+
android:exported="false" />
2023
<activity
2124
android:name=".SplashActivity"
2225
android:exported="true">
@@ -26,12 +29,10 @@
2629
<category android:name="android.intent.category.LAUNCHER" />
2730
</intent-filter>
2831
</activity>
29-
<activity
30-
android:name=".MainActivity"
31-
android:exported="true" />
32+
3233
<meta-data
33-
android:name="com.kakao.sdk.AppKey"
34-
android:value="@string/KAKAO_KEY" />
34+
android:name="com.naver.maps.map.CLIENT_ID"
35+
android:value="@string/NAVER_CLIENT_ID" />
3536
</application>
3637

3738
</manifest>

app/src/main/java/com/woozoo/menumeonya/MainActivity.kt

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package com.woozoo.menumeonya
2+
3+
import android.Manifest
4+
import android.content.pm.PackageManager
5+
import android.location.Location
6+
import android.location.LocationListener
7+
import android.location.LocationManager
8+
import android.os.Bundle
9+
import androidx.appcompat.app.AppCompatActivity
10+
import androidx.core.content.ContextCompat
11+
import com.naver.maps.geometry.LatLng
12+
import com.naver.maps.map.CameraUpdate
13+
import com.naver.maps.map.LocationTrackingMode
14+
import com.naver.maps.map.MapView
15+
import com.naver.maps.map.NaverMap
16+
import com.naver.maps.map.util.FusedLocationSource
17+
18+
class NaverActivity : AppCompatActivity(), LocationListener {
19+
20+
private lateinit var mapView: MapView
21+
private lateinit var locationSource: FusedLocationSource
22+
private lateinit var naverMap: NaverMap
23+
24+
private lateinit var locationManager: LocationManager
25+
26+
companion object {
27+
private const val LOCATION_PERMISSION_REQUEST_CODE = 1000
28+
}
29+
30+
override fun onCreate(savedInstanceState: Bundle?) {
31+
super.onCreate(savedInstanceState)
32+
setContentView(R.layout.activity_naver)
33+
34+
mapView = findViewById(R.id.naver_map)
35+
mapView.onCreate(savedInstanceState)
36+
37+
locationSource =
38+
FusedLocationSource(this, LOCATION_PERMISSION_REQUEST_CODE)
39+
40+
mapView.getMapAsync {
41+
this.naverMap = it
42+
naverMap.locationSource = locationSource
43+
naverMap.locationTrackingMode = LocationTrackingMode.NoFollow
44+
45+
val uiSetting = naverMap.uiSettings
46+
uiSetting.isLocationButtonEnabled = true
47+
48+
if (checkPermission()) {
49+
locationManager.requestLocationUpdates(
50+
LocationManager.NETWORK_PROVIDER, 1000, 10f, this)
51+
}
52+
}
53+
54+
locationManager = getSystemService(LOCATION_SERVICE) as LocationManager
55+
}
56+
57+
override fun onRequestPermissionsResult(requestCode: Int,
58+
permissions: Array<String>,
59+
grantResults: IntArray) {
60+
if (locationSource.onRequestPermissionsResult(requestCode, permissions,
61+
grantResults)) {
62+
if (!locationSource.isActivated) { // 권한 거부됨
63+
naverMap.locationTrackingMode = LocationTrackingMode.None
64+
}
65+
return
66+
}
67+
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
68+
}
69+
70+
71+
72+
override fun onStart() {
73+
super.onStart()
74+
mapView.onStart()
75+
76+
if (checkPermission()) {
77+
locationManager.requestLocationUpdates(
78+
LocationManager.NETWORK_PROVIDER, 1000, 10f, this)
79+
}
80+
}
81+
82+
private fun checkPermission(): Boolean {
83+
return ContextCompat.checkSelfPermission(this,
84+
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_DENIED
85+
}
86+
87+
override fun onResume() {
88+
super.onResume()
89+
mapView.onResume()
90+
}
91+
92+
override fun onPause() {
93+
super.onPause()
94+
mapView.onPause()
95+
}
96+
97+
override fun onSaveInstanceState(outState: Bundle) {
98+
super.onSaveInstanceState(outState)
99+
mapView.onSaveInstanceState(outState)
100+
}
101+
102+
override fun onStop() {
103+
super.onStop()
104+
mapView.onStop()
105+
}
106+
107+
override fun onDestroy() {
108+
super.onDestroy()
109+
mapView.onDestroy()
110+
}
111+
112+
override fun onLowMemory() {
113+
super.onLowMemory()
114+
mapView.onLowMemory()
115+
}
116+
117+
override fun onLocationChanged(location: Location) {
118+
if (location == null) {
119+
return
120+
}
121+
122+
val coord = LatLng(location)
123+
124+
val locationOverlay = naverMap.locationOverlay
125+
locationOverlay.isVisible = true
126+
locationOverlay.position = coord
127+
locationOverlay.bearing = location.bearing
128+
129+
naverMap.moveCamera(CameraUpdate.scrollTo(coord))
130+
}
131+
}

app/src/main/java/com/woozoo/menumeonya/SplashActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SplashActivity : AppCompatActivity() {
2828
if (!checkPermission()) {
2929
requestPermission()
3030
} else {
31-
startActivity(Intent(this, MainActivity::class.java))
31+
startActivity(Intent(this, NaverActivity::class.java))
3232
finish()
3333
}
3434
}
@@ -79,7 +79,7 @@ class SplashActivity : AppCompatActivity() {
7979
showDialogForLocationServiceSetting()
8080
}
8181

82-
startActivity(Intent(this, MainActivity::class.java))
82+
startActivity(Intent(this, NaverActivity::class.java))
8383
finish()
8484
} else {
8585
Toast.makeText(this, "위치 권한이 거절되었습니다", Toast.LENGTH_SHORT).show()
-1.94 MB
Binary file not shown.
-1.45 MB
Binary file not shown.
-1.49 MB
Binary file not shown.

0 commit comments

Comments
 (0)