การตั้งค่า ArcGIS
ขั้นตอนการใช้ ArcGIS Maps SDK for Kotlin จาก MapConductor เพิ่มที่เก็บของ Esri และส่งคีย์ API ผ่านไฟล์ Manifest รองรับทั้งมุมมอง 2D และ 3D
ก่อนเริ่ม
รับคีย์ API
- สร้างบัญชีนักพัฒนา ArcGIS
- เปิด ArcGIS Developer Dashboard
- สร้างแอปพลิเคชันและออกคีย์ API พร้อมขอบเขตที่จำเป็น
เพิ่มที่เก็บของ Esri
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// Esri public repository for ArcGIS Maps SDK
maven {
url = uri("https://esri.jfrog.io/artifactory/arcgis")
}
}
}ติดตั้ง Secrets Gradle Plugin
กลไกเพื่อหลีกเลี่ยงการนำคีย์ไปใส่ในการจัดการซอร์สโค้ด ปลั๊กอินจะอ่าน secrets.properties และแทรกค่าลงในตัวยึดตำแหน่งใน AndroidManifest.xml ขณะบิลด์
plugins {
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") version "2.0.1" apply false
}เพิ่มการพึ่งพา
ฝั่ง ArcGIS ก็ใช้ BOM เช่นกัน จำเป็นต้องมี toolkit สำหรับ Compose ด้วย
plugins {
// ... other plugins
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
}
dependencies {
// ArcGIS Maps SDK
implementation(platform("com.esri:arcgis-maps-kotlin-toolkit-bom:300.1.0"))
implementation("com.esri:arcgis-maps-kotlin:300.1.0")
implementation("com.esri:arcgis-maps-kotlin-toolkit-geoview-compose")
implementation("com.esri:arcgis-maps-kotlin-toolkit-authentication")
// MapConductor BOM pins every module below
implementation(platform("com.mapconductor:mapconductor-bom:1.3.1"))
implementation("com.mapconductor:core")
implementation("com.mapconductor:for-arcgis")
}ตั้งค่า Manifest และคีย์
<manifest>
<!-- Add internet and location permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application>
<!-- ArcGIS API Key -->
<meta-data
android:name="ARCGIS_API_KEY"
android:value="${ARCGIS_API_KEY}" />
</application>
</manifest>ARCGIS_API_KEY=your_actual_arcgis_api_key_here
ตั้งค่าใบอนุญาต (เฉพาะรุ่นการผลิตเท่านั้น)
ไม่จำเป็นสำหรับการแสดงแผนที่พื้นฐานเท่านั้น สำหรับการแจกจ่ายรุ่นการผลิต ให้ตั้งค่าใบอนุญาตตามเอกสารของ Esri
// In your Application class or MainActivity
// ArcGISEnvironment.setLicense("your_license_key_here") // Optional for basic useตรวจสอบ
สิ่งที่ควรเห็น
เมื่อแผนที่ ArcGIS ปรากฏขึ้นและซูม เลื่อน และ (ในมุมมอง 3D) ทำมุมมองเอียงได้ ถือว่าเสร็จสิ้น
@Composable
fun TestArcGIS(modifier: Modifier = Modifier) {
val mapState = rememberArcGISMapViewState(
cameraPosition = MapCameraPosition(
position = GeoPoint(35.6762, 139.6503),
zoom = 12.0,
),
)
// If the map appears, the setup is correct.
// ArcGISMapView is the 3D scene view; ArcGISMapView2D shares the same state.
ArcGISMapView(modifier = modifier, state = mapState)
}ดีไซน์แผนที่
ArcGISDesign รองรับแผนที่ฐานของ Esri สิ่งที่แสดงไว้ที่นี่คือบางส่วนเท่านั้น ในความเป็นจริงมีค่าคงที่มากกว่านี้
การแก้ปัญหา
แผนที่ไม่โหลด
- ตรวจสอบว่าคีย์ API ใน secrets.properties ถูกต้องหรือไม่
- ตรวจสอบใน Dashboard ว่าคีย์มีขอบเขตที่จำเป็นหรือไม่
เกิดข้อผิดพลาดใบอนุญาต
- สำหรับการแจกจ่ายรุ่นการผลิต ให้ตั้งค่าใบอนุญาตตามเอกสารของ Esri
การสร้างไม่สำเร็จ
- ตรวจสอบว่าพิกัดและเวอร์ชันของ Map SDK ตรงกับการระบุในไฟล์ catalog เวอร์ชันหรือไม่
- ตรวจสอบว่าคำจำกัดความของที่เก็บอยู่ใน settings.gradle.kts หรือไม่ (หาก repositoriesMode เป็น FAIL_ON_PROJECT_REPOS ที่เก็บด้านโมดูลจะถูกละเว้น)
- หากมีหลายแผนที่ SDK พร้อมกัน ให้ตรวจสอบความขัดแย้งของการพึ่งพาด้วย ./gradlew :app:dependencies
ถัดไป
ArcGISMapView สำหรับ 3D, ArcGISMapView2D สำหรับ 2D เนื่องจากทั้งสองใช้วัตถุสถานะเดียวกัน จึงสามารถสลับได้ในขณะทำงาน