Thread
#multiplatform
    Michael Paus

    Michael Paus

    3 months ago
    Is there already any multiplatform solution to show a location on an external map. Something that you would do in Android via https://developers.google.com/maps/documentation/urls/android-intents
    Alejandro Moya

    Alejandro Moya

    3 months ago
    that’s platform specific, I don’t think that there will be anything like that available in multiplatform
    you can create a method on each platform to do that and have an expect on the commonMain, that way you’ll be able to do it
    Michael Paus

    Michael Paus

    3 months ago
    If I can do it via expect/actual then anybody could have already done it and that’s what I was asking for. Just trying to avoid duplicate work. (Besides I don’t know how to do that on iOS.)
    Alejandro Moya

    Alejandro Moya

    3 months ago
    fun openMaps(lat: Long, lon: Long) {
        if (UIApplication.sharedApplication.canOpenURL(
                NSURL.URLWithString("comgooglemaps://")!!)
        ) {
            UIApplication.sharedApplication.openURL(
                NSURL.URLWithString(
                    "comgooglemaps://?saddr=&daddr=$lat,$lon&directionsmode=driving"
                )!!
            )
        }
    }
    that would be the ios implementation on multiplatform, I would first check if there’s access to the shared application from the library
    @Michael Paus I’ve been reading and you can’t access the app from a framework on ios, I think the same applies to android, this means you should pass the application object on ios and the context on android, you can achieve this by using typealias and create a common
    ApplicationObject
    type
    actual typealias APPObject = UIApplication
    
    fun openMaps(appObject: APPObject, lat: Long, lon: Long) {
        if (appObject.canOpenURL(
                NSURL.URLWithString("comgooglemaps://")!!)
        ) {
            appObject.openURL(
                NSURL.URLWithString(
                    "comgooglemaps://?saddr=&daddr=$lat,$lon&directionsmode=driving"
                )!!
            )
        }
    }
    that would be the ios implementation
    Michael Paus

    Michael Paus

    3 months ago
    @Alejandro Moya Many thanks. I’ll give that a try as soon as I can.
    Ohh, I just realize that this solution will probably not be usable in general. If I understand the docs correctly this would require the user to have the Google Maps app pre-installed on the device, right? My original question was “… to show a location on an external map.” and I gave the Google Maps example because that is what you would use on Android. On iOS I would instead use whatever is normally used to show a map on such a device without having anything specific being pre-installed by the user. Sorry for the confusion. 😢
    Alejandro Moya

    Alejandro Moya

    3 months ago
    that’s the reference for apple maps
    something like
    "<http://maps.apple.com/?ll=$lat,$lon>"
    Michael Paus

    Michael Paus

    3 months ago
    Ahh, so the code above remains the same and only the URL changes, right?
    Alejandro Moya

    Alejandro Moya

    3 months ago
    fun openMaps(appObject: APPObject, lat: Float, lon: Float) {
        if (appObject.canOpenURL(
                NSURL.URLWithString("<http://maps.apple.com/>")!!)
        ) {
            appObject.openURL(
                NSURL.URLWithString(
                    "<http://maps.apple.com/?ll=$lat,$lon>"
                )!!
            )
        }
    }
    fixed the lat and lon types as they will be Float
    Michael Paus

    Michael Paus

    3 months ago
    It works. With the click of a button I can move to the iOS map at the given location in a multiplatform app.
    One question remains though. How can I get back to my app after I am done with the map?
    Alejandro Moya

    Alejandro Moya

    3 months ago
    that’s regular iOS navigation, the person will switch apps to go back, same as with android