Skip to content

fornewid/naver-map-compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

NAVER Map Compose ๐Ÿ—บ

์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” Jetpack Compose์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋„ค์ด๋ฒ„ ์ง€๋„ API๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Sample App

์ด ์ €์žฅ์†Œ์—๋Š” ์ƒ˜ํ”Œ ์•ฑ์ด ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์‹คํ–‰ํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  1. NAVER Map Android SDK Demo ๋ ˆํฌ์ง€ํ„ฐ๋ฆฌ์˜ How To Run์„ ์ฐธ๊ณ ํ•˜์—ฌ, ํด๋ผ์ด์–ธํŠธ ID๋ฅผ ๋ฐœ๊ธ‰๋ฐ›์Šต๋‹ˆ๋‹ค.
  2. client_id.xml์˜ naver_map_sdk_client_id์— ๋ฐœ๊ธ‰๋ฐ›์€ ํด๋ผ์ด์–ธํŠธ ID๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  3. ๋นŒ๋“œํ•˜๊ณ  ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

Download

naver-map-compose:

Compose 1.1 (1.1.x)Maven Central
Compose 1.2 (1.2.x)Maven Central
Compose 1.3 (1.3.x)Maven Central
Compose 1.4 (1.4.x)Maven Central
Compose 1.5 (1.5.x)Maven Central
Compose 1.6 (1.6.x)Maven Central
Compose 1.7 (1.7.x)Maven Central
Compose 1.8 (1.8.x)Maven Central

naver-map-location:

play-services-location 16.0.0 ~Maven Central
play-services-location 18.0.0 ~Maven Central
play-services-location 21.0.1 ~Maven Central
repositories {
    mavenCentral()
}

dependencies {
    implementation 'io.github.fornewid:naver-map-compose:<version>'

    // (Optional) ์œ„์น˜ ์ถ”์ ํ•˜๊ธฐ
    // ๋‹ค๋ฅธ ๋ฒ„์ „์˜ play-services-location ๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์„ ์–ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
    // ์„ ์–ธํ•˜์ง€ ์•Š์•˜์„ ๋•Œ, ๊ธฐ๋ณธ์œผ๋กœ ํฌํ•จ๋˜๋Š” play-services-location ๋ฒ„์ „์€ 16.0.0 ์ž…๋‹ˆ๋‹ค.
    implementation 'io.github.fornewid:naver-map-location:<version>'
}

โš ๏ธ Warnings

์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋‚ด๋ถ€์ ์œผ๋กœ ๋„ค์ด๋ฒ„ ์ง€๋„ SDK๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์ด์— ๋”ฐ๋ผ์˜ค๋Š” ๋ช‡ ๊ฐ€์ง€ ์ฃผ์˜์‚ฌํ•ญ์ด ์žˆ์Šต๋‹ˆ๋‹ค. (์ฐธ๊ณ : ๋„ค์ด๋ฒ„ ์ง€๋„ ์•ˆ๋“œ๋กœ์ด๋“œ SDK - ์‹œ์ž‘ํ•˜๊ธฐ - ์˜์กด์„ฑ ์ถ”๊ฐ€)

  1. ๋„ค์ด๋ฒ„ ์ง€๋„ SDK๋Š” https://repository.map.naver.com/archive/maven Maven ์ €์žฅ์†Œ์—์„œ ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ฃจํŠธ ํ”„๋กœ์ ํŠธ์˜ build.gradle์— ์ €์žฅ์†Œ ์„ค์ •์„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  allprojects {
      repositories {
          google()
          mavenCentral()
+         maven {
+             url 'https://repository.map.naver.com/archive/maven'
+         }
          // naver-map-compose 1.5.6 ๋ฒ„์ „๊นŒ์ง€๋Š” ๋‹ค๋ฅธ Maven ์ €์žฅ์†Œ ์ฃผ์†Œ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
          // maven { url 'https://naver.jfrog.io/artifactory/maven/' }
      }
  }
  1. ์˜ˆ์ „ ๋„ค์ด๋ฒ„ ์ง€๋„ SDK๋Š” appcompat-v7 28 ๋ฒ„์ „์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. naver-map-compose 1.5.6 ๋ฒ„์ „๊นŒ์ง€๋Š”, gradle.properties์— Jetifier ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. naver-map-compose 1.5.7 ๋ฒ„์ „๋ถ€ํ„ฐ๋Š” ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
android.useAndroidX=true
android.enableJetifier=true
  1. ๋„ค์ด๋ฒ„ ์ง€๋„ SDK๋Š” ์œ„์น˜ ์ถ”์ ๊ธฐ๋Šฅ์„ ์ง€์›ํ•˜๋ ค๊ณ , play-services-location ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ 16.0.0 ๋ฒ„์ „์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ฒ„์ „๋ณด๋‹ค ๋†’์€ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋ฉด, ์ปดํŒŒ์ผ ํ˜น์€ ๋Ÿฐํƒ€์ž„์— ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋•Œ๋Š” play-services-location ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฒ„์ „๊ณผ ๊ฐ™์€ naver-map-location ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€๋กœ ์„ ์–ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  dependencies {
      implementation 'io.github.fornewid:naver-map-compose:<version>'
      implementation 'com.google.android.gms:play-services-location:21.0.1'
+     implementation 'io.github.fornewid:naver-map-location:21.0.2'
  }

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
  • LocationOverlay
  • Marker
  • MultipartPathOverlay
  • PathOverlay
  • PolygonOverlay
  • PolylineOverlay

raw NaverMap ๊ฐ์ฒด ์–ป๊ธฐ (Experimental)

ํŠน์ • UseCase์—์„œ๋Š” NaverMap ๊ฐ์ฒด๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ๋งˆ์ปค ํด๋Ÿฌ์Šคํ„ฐ๋ง์€ ์•„์ง ์ง€์›๋˜์ง€ ์•Š์ง€๋งŒ(Issue #14 ์ฐธ์กฐ), ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฅผ ์ด์šฉํ•˜์—ฌ ํด๋Ÿฌ์Šคํ„ฐ๋ง์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๊ตฌํ˜„ํ•˜๋ ค๋ฉด MapEffect ํ˜น์€ DisposableMapEffect composable์„ ์‚ฌ์šฉํ•˜์—ฌ ๋„ค์ด๋ฒ„์ง€๋„ SDK์˜ raw NaverMap ๊ฐ์ฒด์— ์ ‘๊ทผํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

NaverMap(
    // ...
) {
    val context = LocalContext.current
    var clusterManager by remember { mutableStateOf<TedNaverClustering<MyItem>?>(null) }
    DisposableMapEffect(items) { map ->
        if (clusterManager == null) {
            clusterManager = TedNaverClustering.with<MyItem>(context, map).make()
        }
        clusterManager?.addItems(items)
        onDispose {
            clusterManager?.clearItems()
        }
    }
}

์œ„์น˜ ์ถ”์ ํ•˜๊ธฐ

โš ๏ธ play-services-location ๋ฒ„์ „์ด 16.0.0 ๋ณด๋‹ค ๋†’์œผ๋ฉด, ์ปดํŒŒ์ผ ํ˜น์€ ๋Ÿฐํƒ€์ž„์— ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (Warnings ์„น์…˜์„ ์ฐธ๊ณ ํ•˜์„ธ์š”.)

๊ตฌ๊ธ€์—์„œ ์ œ๊ณตํ•˜๋Š” FusedLocationProviderClient์„ ์ด์šฉํ•˜์—ฌ, ์œ„์น˜๋ฅผ ์ถ”์ ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

MapProperties์˜ locationTrackingMode๋ฅผ ์„ค์ •ํ•˜์—ฌ ์œ„์น˜ ์ถ”์  ๋ชจ๋“œ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

NaverMap(
    locationSource = rememberFusedLocationSource(),
    properties = MapProperties(
        locationTrackingMode = LocationTrackingMode.Follow,
    ),
    uiSettings = MapUiSettings(
        isLocationButtonEnabled = true,
    )
)

LocationTrackingMode๊ฐ€ Follow ๋˜๋Š” Face์ผ ๋•Œ, ๋‚˜์นจ๋ฐ˜ ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™”ํ•˜๋ ค๋ฉด isCompassEnabled์„ true๋กœ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

NaverMap(
    locationSource = rememberFusedLocationSource(isCompassEnabled = true),
    properties = MapProperties(
        locationTrackingMode = LocationTrackingMode.Face,
    ),
    uiSettings = MapUiSettings(
        isLocationButtonEnabled = true,
    )
)

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.