Beta
Maps on Android
Today: com.ranamaps:maps-android 0.1.0-beta.1 is built and tested, not published yet. Ask
hello@ranamaps.com for early access.
Coverage: roads cover all of Nigeria once the Nigeria release is deployed (built, not live yet; production is Lagos only today). Lagos has the most street names, places, stops and gates.
Install
One dependency, from Rana's Maven repository. Minimum Android 8.0 (API 26).
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven("https://assets.ranamaps.com/maven")
}
}
// app/build.gradle.kts
dependencies {
implementation("com.ranamaps:maps-android:0.1.0-beta.1")
}
Compose
@Composable
fun TripMap() {
val from = LatLng(6.5095, 3.3711)
val to = LatLng(6.6018, 3.3515)
RanaMap(
key = BuildConfig.RANA_PUBLIC_KEY,
modifier = Modifier.fillMaxSize(),
style = RanaStyle.Day,
center = LatLng(6.5244, 3.3792), // Lagos
zoom = 12.0,
) { map ->
map.addMarker(from, label = "A")
map.addMarker(to, color = "#1c7ed6", label = "B")
map.fitPoints(listOf(from, to))
}
// Shows "© Rana Maps © OpenStreetMap"; it cannot be switched off.
}
For XML layouts, use com.ranamaps.sdk.map.RanaMapView, call start(key, …) { map -> … } once, and forward the
activity's onStart, onResume, onPause, onStop and onDestroy.
The map controller
onReady gives a RanaMapController:
| Method | What it does |
|---|---|
moveTo(center, zoom, animate) |
Move the camera |
center, zoom |
Read the camera |
fitPoints(points, paddingPx) |
Show every point |
setStyle(RanaStyle.Night) |
Change the style |
addMarker(point, color, label) |
A marker; returns one with setPosition and remove |
showRoute(route), showLine(points) |
A route line; returns one with remove |
setOnMapClickListener { point -> } |
Taps |
Web services
// In a coroutine. ClientIdentity sends your package name and signing certificate for the key's Android restriction.
val client = RanaClient(BuildConfig.RANA_PUBLIC_KEY, ClientIdentity.of(context))
val result = client.directions(Location.Point(LatLng(6.5095, 3.3711)), Location.Point(LatLng(6.6018, 3.3515)), Mode.Keke)
result.routes.firstOrNull()?.let { map.showRoute(it) }
// result.attribution is "© Rana Maps © OpenStreetMap".
Notes
- The key must be a public key limited to your package name and the SHA-256 of your signing certificate (with Play App Signing, the Play certificate). The SDK sends both and adds the key to Rana's map requests only.
- Never put a secret key (
sk_) in an app. - Every failure is a
RanaErrorwith the API'scode, the HTTPstatus, therequestIdandretryAfterSeconds. - Health telemetry (never location):
RanaMaps.telemetry = falseturns it off. See telemetry and privacy.