A library to convert Uber's H3 geo-index to LatLng vertices for Kotlin Multiplatform Mobile iOS and android
- Uber H3 in one interface
- Common interface available on KMM Shared
- iOS
- Deployment Target 9.0 or higher
- Android
- minSdkVersion 21
Add this gradle settings into your KMP(Kotlin Multiplatform Project)
plugins {
id("com.android.library")
kotlin("multiplatform")
}
val h3Lib = "com.linecorp.abc:kmm-h3:0.1.7"
kotlin {
android()
ios {
binaries
.filterIsInstance<Framework>()
.forEach {
it.baseName = "shared"
it.transitiveExport = true
it.export(h3Lib)
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(h3Lib)
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
implementation(h3Lib)
api(h3Lib)
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13.2")
implementation("androidx.test:core:1.0.0")
implementation("androidx.test:runner:1.1.0")
implementation("org.robolectric:robolectric:4.2")
}
}
val iosMain by getting {
dependencies {
implementation(h3Lib)
api(h3Lib)
}
}
val iosTest by getting
}
}
Android
- Copy and paste
jniLibs
folder into src/main in your project
iOS
- Cocoapods
-
Create
Podfile
with below setting in your project root.use_frameworks! platform :ios, '9.0' install! 'cocoapods', :deterministic_uuids => false target 'iosApp' do pod 'shared', :path => '../shared/' end
-
Run command
pod install
on the terminal
Android
val h3Indexes = listOf(
"87283082bffffff",
"872830870ffffff",
"872830820ffffff",
"87283082effffff",
)
val polygons = H3.polygons(h3Indexes)
/*
[Polygon(h3Index=87283082bffffff, vertices=[LatLng(lat=37.78529347359727, lng=-122.41077092287513), LatLng(lat=37.79707086149341, lng=-122.40326874464051), LatLng(lat=37.80760100422449, lng=-122.41208776737979), ...
*/
iOS
let h3Indexes = [
"87283082bffffff",
"872830870ffffff",
"872830820ffffff",
"87283082effffff",
]
let polygons = H3.Companion().polygons(h3Indexes: h3Indexes)
print("polygons", polygons)
/*
[Polygon(h3Index=87283082bffffff, vertices=[LatLng(lat=37.78529347359727, lng=-122.41077092287512), LatLng(lat=37.79707086149341, lng=-122.4032687446405), LatLng(lat=37.80760100422449, lng=-122.41208776737977), ...
*/
- Get Geo Boundaries