https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

Sergei Sevriugin

11/06/2023, 1:33 PM
Hey, guys, question about maps. Can we use original map services for iOS (Apple) and Android (Google) in one KMM application, thanks 🙏
d

Darron Schall

11/06/2023, 3:15 PM
Yes, but you have to write platform-specific code to render the maps on each platform. The app I'm leading uses Apple Maps with SwiftUI on the iOS side, and Google Maps with Compose on the Android side. The trick is to use an interface/common data class for the annotations. All of my business logic is shared and deals with common data types. My shared view model creates the annotations to display, then I have platform-specific refinements that convert my shared annotation to something platform-specific to place within each platform's map framework. On iOS my shared annotation converts to a
CLLocationCoordinate2D
and on Android it converts to
com.google.android.gms.maps.model.LatLng
s

Sergei Sevriugin

11/06/2023, 3:20 PM
Very cool, thanks a lot @Darron Schall . Is it open project, I mean is it possible to look at app architecture?
d

Darron Schall

11/06/2023, 3:48 PM
No, it's not open source. But, you can see the same type of ideas in the open-source moko-maps library - https://github.com/icerockdev/moko-maps/tree/master. See, e.g. https://github.com/icerockdev/moko-maps/blob/master/maps-mapbox/src/iosMain/kotlin/dev/icerock/moko/maps/mapbox/Utils.kt#L23
s

Sergei Sevriugin

11/06/2023, 3:50 PM
🙏
2 Views