Skip to content
farimarwatPublic

About

No description, website, or topics provided.

Resources

Stars

50 stars

Watchers

0 watching

Forks

Repository files navigation

🗺️ KrossMap

KrossMap is a Kotlin Multiplatform maps library for Compose Multiplatform. One Compose API draws Google Maps on Android and Apple MapKit on iOS, natively on each platform, with markers, shapes, camera control, location and native map controls.

Whether you're building a delivery app, ride tracker, or location-based feature, KrossMap simplifies the map experience with powerful abstractions and built-in utilities.

🚀 Features

  • 🧩 Declarative content: Marker, Polyline, Polygon, Circle inside KrossMap { }
  • 🧭 Animated markers that point along their heading, with labels
  • 📷 Camera you can read, animate, and fit to bounds; follow mode like Google Maps / Apple Maps
  • 📍 Location state with heading, permission status and errors, plus the native location dot
  • 🔘 Native controls: Liquid Glass buttons on iOS 26, Material 3 on Android
  • 👆 Map, marker and shape tap events
  • 🌗 Map types, dark mode, custom styling, zoom limits, content padding
  • 🌍 Kotlin Multiplatform: Android & iOS

📦 Dependency

To add KrossMap to your project, include the following in your shared module's build.gradle.kts:

dependencies {
    implementation("io.github.farimarwat:krossmap:2.0")
}

Requires Kotlin 2.3.21 or newer. On Android, add your Google Maps API key to the manifest (com.google.android.geo.API_KEY). The library does not ask for location permission itself; request it in your app (the demo uses moko-permissions).

📍 Getting Started

1. Show a map

val camera = rememberKrossCameraPositionState(latitude = 32.6037, longitude = 70.9217, zoom = 15f)

KrossMap(
    modifier = Modifier.fillMaxSize(),
    cameraPositionState = camera,
)

2. Add markers and shapes

Everything inside KrossMap { } is on the map; remove it from the composition and it leaves the map.

KrossMap(cameraPositionState = camera) {
    Marker(
        state = rememberKrossMarkerState(KrossCoordinate(32.6037, 70.9217)),
        title = "Shop",
        icon = KrossMarkerIcon.Vector(Icons.Default.Store, tint = Color.Red),
        onClick = { println("Shop tapped"); true },
    )
    Polyline(points = route, color = Color.Blue, width = 6.dp)
    Polyline(points = walk, color = Color.Gray, width = 4.dp, dashLength = 8.dp)
    Polygon(points = area, fillColor = Color.Red.copy(alpha = 0.25f), strokeColor = Color.Red, holes = listOf(courtyard))
    Circle(center = start, radiusMeters = 150.0, fillColor = Color.Green.copy(alpha = 0.2f))
}

Marker icons can be PNG bytes (KrossMarkerIcon.Bytes), an ImageBitmap, an ImageVector or any Painter. Set markerState.position to move a marker; the move is animated (animationMillis, default 1000).

3. Location, following and controls

val location = rememberKrossLocationState()
val player = rememberKrossMarkerState(start)
LaunchedEffect(location.currentLocation) { location.currentLocation?.let { player.position = it } }

KrossMap(
    cameraPositionState = camera,
    locationState = location,
    properties = KrossMapProperties(showMyLocation = true),
    controls = listOf(KrossMapControl.MyLocation, KrossMapControl.Toggle3D, KrossMapControl.Follow),
) {
    Marker(state = player, title = "Me", icon = carIcon, rotation = location.currentLocation?.bearing ?: 0f)
}
  • KrossMapControl.Follow starts location updates and makes the camera follow position and heading; dragging the map turns following off.
  • location.currentLocation, isUpdating, hasPermission and locationError are Compose state. Updates pause in the background and stop when the state leaves composition.
  • Add your own buttons with KrossMapControl.Custom(id, iosSymbol, icon, contentDescription, onClick = { }).

4. Camera

scope.launch { camera.animateCamera(latitude = lat, longitude = lng, zoom = 17f, tilt = 45f) }
camera.moveCamera(zoom = 12f)                       // no animation
scope.launch { camera.animateToBounds(route) }       // fit points on screen
Text("zoom ${camera.position.zoom}")                 // live position; camera.isMoving too

5. Appearance and events

KrossMap(
    cameraPositionState = camera,
    properties = KrossMapProperties(
        mapType = KrossMapType.Hybrid,
        colorScheme = KrossMapColorScheme.System,   // or Light / Dark
        maxZoom = 19f,
        showTraffic = true,
    ),
    contentPadding = PaddingValues(bottom = 120.dp), // keep controls and logo above a bottom sheet
    onMapClick = { coordinate -> },
    onMapLongClick = { coordinate -> },
    onCameraIdle = { position -> },
)

Platform extras: androidMapStyleJson (a Google Maps style) and iosPointOfInterestCategories (for example setOf("MKPOICategoryRestaurant")).


Version History

🚀 What's New in KrossMap v2.0

  1. 🧩 Declarative map content: Marker, Polyline (solid or dashed), Polygon (with holes) and Circle, each with zIndex and onClick, declared inside KrossMap { }.
  2. 📍 KrossLocationState: location on its own, with heading, hasPermission, isUpdating and locationError; showMyLocation shows the native location dot.
  3. 🔘 Native controls: My Location, 2D/3D, Follow and custom buttons. Liquid Glass with SF Symbols on iOS 26+ (blur material on earlier iOS), Material 3 on Android.
  4. 📷 Camera: live position and isMoving, moveCamera, animateToBounds; zoom means the same on both platforms; durationMillis is respected; following turns off when the user drags the map.
  5. 🌗 Appearance: map types, dark mode, custom styles, POI filters, minZoom/maxZoom, contentPadding.
  6. 🏷️ Consistent markers: icons centered on their coordinate and rotated to their heading even when the map rotates or tilts; titles in a label underneath on both platforms.
  7. 🛠️ Reliability: iOS keeps markers and shapes in sync (add, update, remove); smooth heading without GPS jitter; location stops in the background; line widths in dp look the same on both platforms; no Activity leaks.

⬆️ Migrating from 1.x

1.x code keeps compiling and working: KrossMapState, rememberKrossMapState() and KrossMap(mapState = …) are deprecated wrappers over the 2.0 API. To migrate:

1.x 2.0
rememberKrossMapState() rememberKrossLocationState() for location; markers and shapes go in KrossMap { }
mapState.addOrUpdateMarker(KrossMarker(coordinate, title, icon)) Marker(state = rememberKrossMarkerState(coordinate), title = title, icon = KrossMarkerIcon.Bytes(icon)) and set state.position to move it
mapState.removeMarker(marker) stop declaring the Marker
mapState.addPolyLine(KrossPolyLine(points, color = c, width = w)) Polyline(points, color = c, width = w.dp)
mapState.startLocationUpdate() / stopLocationUpdate() location.startUpdates() / stopUpdates(), or the Follow control
mapState.onUpdateLocation = { } read location.currentLocation (Compose state)
KrossMap(mapState = …, onMarkerClick = { }) KrossMap(locationState = …) { Marker(onClick = { }) }
mapSettings = { MyButtons() } controls = listOf(…), or overlay your own UI in a Box

Other changes from 1.3:

  • Polyline width is in dp (1.3 used Android pixels: divide old values by about 2.75).
  • Marker icons are centered on their coordinate (on Android they used to sit above it).
  • KrossCoordinate.bearing and KrossMarker.coordinate are val (use copy()); calculateBearing returns 0–360°.
  • showTraffic is off by default; KrossMapState.currentLocation is read-only.

🚀 What's New in KrossMap v1.3

  1. 🧭 Improved Camera Controls on iOS

    • Enhanced support for camera tilting and direction handling on iOS.
  2. ⚙️ New Map Properties API

    • Introduced KrossMapProperties to control:
      • 🏙️ showBuildings – Toggle 3D building rendering
      • 📍 showPointOfInterest – Show points of interest (iOS only)
      • 🚗 showTraffic – Enable real-time traffic overlay
      • 🔄 enableRotationGesture – Allow user rotation
      • 🧭 enableTiltGesture – Allow tilting with gestures
      • 🖐️ enableScrollGesture – Enable panning/scrolling

🤝 Contribute

KrossMap is open-source and welcomes contributions!
If you find a bug, have a feature request, or want to improve the library, feel free to open an issue or submit a pull request.

Check the issues section for things you can help with.


👨‍💻 About Me

Hi, I’m Farman Ullah Khan – a passionate Android & Kotlin Multiplatform developer.
I love building open-source tools that simplify cross-platform development and improve developer experience.

You can connect with me on LinkedIn or check out my other projects on GitHub.

About

No description, website, or topics provided.

Resources

Stars

50 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages