iOS Question Geo URL Scheme

fbritop

Active Member
Licensed User
Longtime User
I use this code, in Android, so the user can choose which Map App we wants to open the route.

B4X:
Sub btnDirections_Click
    Dim p As B4XView=Sender
    Dim propiedad As Map=p.Tag
    
    #if b4a
    Dim geouri As String= "geo:" & propiedad.get("lat") & "," & propiedad.get("lon") & "?q=" & propiedad.get("lat") & "," & propiedad.get("lon")
    Dim mIntent As Intent
    mIntent.Initialize(mIntent.ACTION_VIEW, geouri)
    StartActivity(mIntent)
    #end if
    #if b4i
    
    #End If
End Sub

Which leads in Android to:
1629900346209.png

Is there something similar in iOS, so in order that we dont force the user to certain App?
 

fbritop

Active Member
Licensed User
Longtime User
Thanks,
but again, the main question is if the user can choose the app, based that the URI is a location URI. I can check installed apps, but it is not only google that gives you direction or transport that it can be useful for the user.

GMaps
Uber
Didi
Cabify
Grin
Lime
Scoot
Hop
Lift
Curb
Bolt
Careem
EasyTaxi

And the list can keep growing.... If it is not possible I´m ok, wont offer the link through the app, but I cannot be updating the list every time an app goes on the market

You will need to do it yourself.
Add to Main:
B4X:
#QueriesSchemes: comgooglemaps
Later you can check whether Google Maps is installed with:
B4X:
If Main.App.CanOpenURL("comgooglemaps://") ..
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
the main question is if the user can choose the app, based that the URI is a location URI
I would assume this is something other people have wanted also. So I would search Stack Overflow for topics on it, and also look in the App Store for app with addresses, to see what happens when you tap the address.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I did try various suggestions based on sending vcards.

It didn't seem to work.
If you like to try:
B4X:
Private Sub Button1_Click
    Dim avc As ActivityViewController
    File.WriteString(File.DirTemp, "vcard.vcf", CreateVCard(36.4545, 32.2323))
    Dim b() As Byte = CreateVCard(36.4545, 32.2323).GetBytes("utf8")
    Dim ItemProvider As NativeObject
    ItemProvider.Initialize("NSItemProvider").RunMethod("alloc", Null).RunMethod("initWithItem:typeIdentifier:", Array(ItemProvider.ArrayToNSData(b), "public.vcard"))
    avc.Initialize("avc", Array(ItemProvider))
    avc.Show(B4XPages.GetNativeParent(Me), Root) 'Second parameter is relevant for iPad only. The arrow will point to the view.
    Wait For avc_Complete (Success As Boolean, ActivityType As String)
    Log($"Success: ${Success}, ActivityType: ${ActivityType}"$)
End Sub

Sub CreateFileUrl (Dir As String, FileName As String) As Object
    Dim no As NativeObject
    no = no.Initialize("NSURL").RunMethod("fileURLWithPath:", Array(File.Combine(Dir, FileName)))
    Return no
End Sub

Private Sub CreateVCard(Latitude As Double, Longitude As Double) As String
    Return _
$"BEGIN:VCARD
VERSION:4.0
N:;Shared Location;;;
FN:Shared Location
item1.URL:http://maps.apple.com/?ll=${Latitude},${Longitude}
item1.X-ABLabel:map url
End:VCARD"$
End Sub
(I've also tried to write it to a file and send it with CreateFileUrl)
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
I've been looking for a way to open maps on ios, and I found this
B4X:
    Dim app As Application
    app.OpenURL("http://maps.apple.com?z=16&q=" & Lat & "," & Lng & "&ll=" & Lat & "," & Lng)
... and the Apple Maps app pops up, drops a pin, and centers the map for the coordinates you send it. It doesn't give the end user a choice of which app to use, but maybe it will help someone. There is a discussion that helped me here: https://developer.apple.com/library...oneURLScheme_Reference/MapLinks/MapLinks.html

Edit: this does NOT work. not on my device anyway
B4X:
Dim app As Application
app.OpenURL("geo:" & Lat & "," & Lng)
 
Last edited:
Upvote 0
Top