naver-map-compose
naver-map-compose copied to clipboard
NAVER Map Android SDK for Jetpack Compose ๐บ
NAVER Map Compose ๐บ
์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ Jetpack Compose์์ ์ฌ์ฉํ ์ ์๋ ๋ค์ด๋ฒ ์ง๋ API๋ฅผ ์ ๊ณตํฉ๋๋ค.
Sample App
์ด ์ ์ฅ์์๋ ์ํ ์ฑ์ด ํฌํจ๋์ด ์์ต๋๋ค. ์คํํ๋ ค๋ฉด ๋ค์์ ์ํํด์ผ ํฉ๋๋ค.
- NAVER Map Android SDK Demo ๋ ํฌ์งํฐ๋ฆฌ์ How To Run์ ์ฐธ๊ณ ํ์ฌ, ํด๋ผ์ด์ธํธ ID๋ฅผ ๋ฐ๊ธ๋ฐ์ต๋๋ค.
-
client_id.xml
์naver_map_sdk_client_id
์ ๋ฐ๊ธ๋ฐ์ ํด๋ผ์ด์ธํธ ID๋ฅผ ์ ๋ ฅํฉ๋๋ค. - ๋น๋ํ๊ณ ์คํํฉ๋๋ค.
Download
Compose 1.1 (1.1.x) | |
Compose 1.2 (1.2.x) | |
Compose 1.3 (1.3.x) |
repositories {
mavenCentral()
}
dependencies {
implementation 'io.github.fornewid:naver-map-compose:<version>'
// NAVER Map Android SDK ์ต์ ๋ฒ์ ๋ ํฌํจํด์ผ ํฉ๋๋ค.
implementation 'com.naver.maps:map-sdk:3.15.0'
// FusedLocationSource๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด play-services-location ์์กด์ฑ๋ ์ถ๊ฐํด์ผ ํฉ๋๋ค.
implementation 'com.google.android.gms:play-services-location:16.0.0'
}
Usage
์ง๋ ์ถ๊ฐํ๊ธฐ
NaverMap(
modifier = Modifier.fillMaxSize()
)
์ง๋ ๊ตฌ์ฑํ๊ธฐ
์ง๋๋ MapProperties
์ MapUiSettings
๊ฐ์ฒด๋ฅผ NaverMap
composable์ ์ ๋ฌํ์ฌ ๊ตฌ์ฑํ ์ ์์ต๋๋ค.
var mapProperties by remember {
mutableStateOf(
MapProperties(maxZoom = 10.0, minZoom = 5.0)
)
}
var mapUiSettings by remember {
mutableStateOf(
MapUiSettings(isLocationButtonEnabled = false)
)
}
Box(Modifier.fillMaxSize()) {
NaverMap(properties = mapProperties, uiSettings = mapUiSettings)
Column {
Button(onClick = {
mapProperties = mapProperties.copy(
isBuildingLayerGroupEnabled = !mapProperties.isBuildingLayerGroupEnabled
)
}) {
Text(text = "Toggle isBuildingLayerGroupEnabled")
}
Button(onClick = {
mapUiSettings = mapUiSettings.copy(
isLocationButtonEnabled = !mapUiSettings.isLocationButtonEnabled
)
}) {
Text(text = "Toggle isLocationButtonEnabled")
}
}
}
์ง๋์ ์นด๋ฉ๋ผ ์ ์ดํ๊ธฐ
CameraPositionState
๋ฅผ ํตํด ์นด๋ฉ๋ผ ๋ณ๊ฒฝ์ ๊ด์ฐฐํ๊ณ ์ ์ดํ ์ ์์ต๋๋ค.
val seoul = LatLng(37.532600, 127.024612)
val cameraPositionState: CameraPositionState = rememberCameraPositionState {
// ์นด๋ฉ๋ผ ์ด๊ธฐ ์์น๋ฅผ ์ค์ ํฉ๋๋ค.
position = CameraPosition(seoul, 11.0)
}
Box(Modifier.fillMaxSize()) {
NaverMap(cameraPositionState = cameraPositionState)
Button(onClick = {
// ์นด๋ฉ๋ผ๋ฅผ ์๋ก์ด ์ค ๋ ๋ฒจ๋ก ์ด๋ํฉ๋๋ค.
cameraPositionState.move(CameraUpdate.zoomIn())
}) {
Text(text = "Zoom In")
}
}
์ง๋์ ๊ทธ๋ฆฌ๊ธฐ
์ง๋์ Marker
์ฒ๋ผ Overlay๋ฅผ ์ถ๊ฐํ๋ ค๋ฉด, NaverMap
์ content์ child composable์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
NaverMap {
Marker(
state = MarkerState(position = LatLng(37.532600, 127.024612)),
captionText = "Marker in Seoul"
)
Marker(
state = MarkerState(position = LatLng(37.390791, 127.096306)),
captionText = "Marker in Pangyo"
)
}
์ ๊ณต๋๋ Overlay๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
-
ArrowheadPathOverlay
-
CircleOverlay
-
GroundOverlay
-
Marker
-
MultipartPathOverlay
-
PathOverlay
-
PolygonOverlay
-
PolylineOverlay
raw NaverMap ๊ฐ์ฒด ์ป๊ธฐ (Experimental)
ํน์ UseCase์์๋ NaverMap
๊ฐ์ฒด๊ฐ ํ์ํฉ๋๋ค.
์๋ฅผ ๋ค์ด, ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ๋ง์ปค ํด๋ฌ์คํฐ๋ง์ ์์ง ์ง์๋์ง ์์ง๋ง(Issue #14 ์ฐธ์กฐ),
์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ฅผ ์ด์ฉํ์ฌ ํด๋ฌ์คํฐ๋ง์ ๊ตฌํํ ์ ์์ต๋๋ค.
์ด๋ ๊ฒ ๊ตฌํํ๋ ค๋ฉด MapEffect
composable์ ์ฌ์ฉํ์ฌ ๋ค์ด๋ฒ์ง๋ SDK์ raw NaverMap
๊ฐ์ฒด์ ์ ๊ทผํด์ผ ํฉ๋๋ค.
NaverMap(
// ...
) {
val context = LocalContext.current
var clusterManager by remember { mutableStateOf<TedNaverClustering<MyItem>?>(null) }
MapEffect(items) { map ->
if (clusterManager == null) {
clusterManager = TedNaverClustering.with<MyItem>(context, map).make()
}
clusterManager?.addItems(items)
}
}
Snapshots
ํ์ฌ ๊ฐ๋ฐ ์ค์ธ ๋ฒ์ ์ ํ์ธํ๊ณ ์ถ๋ค๋ฉด SNAPSHOT ๋ฒ์ ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
Snapshot์ main
branch์ ์ปค๋ฐ์ด ์ถ๊ฐ๋ ๋๋ง๋ค ์
๋ฐ์ดํธ๋ฉ๋๋ค.
repositories {
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
// ์ ๋งํฌ์์ ์ต์ SNAPSHOT ๋ฒ์ ์ ํ์ธํ์ธ์.
classpath 'io.github.fornewid:naver-map-compose:XXX-SNAPSHOT'
}
Contributions
- ์ค๋ฅ๋ฅผ ๋ฐ๊ฒฌํ๊ฑฐ๋ ๊ถ๊ธํ ์ ์ด ์๋ค๋ฉด ์ด์๋ฅผ ๋ฑ๋กํด์ฃผ์ธ์.
- ์๋ก์ด ๊ธฐ๋ฅ์ ์ถ๊ฐํ๊ณ ์ถ๋ค๋ฉด GitHub Issues๋ฅผ ํตํด ์ง์ ๊ฐ๋ฅ ์ฌ๋ถ๋ฅผ ํ์ธํด์ผ ํฉ๋๋ค.
License
Copyright 2022 SOUP
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.