iOS Question How to open Apple maps with address?

QtechLab

Active Member
Licensed User
Longtime User
Hello there,

I read some posts here in B4X forums.
I'm trying to open apple maps from my application, i tryed with this code, got solution from another post
https://www.b4x.com/android/forum/threads/load-maps-using-coordinates.106670/post-667661

This code doesn't open anything

B4X:
If evtUser.ValidAddress Then
  Dim mapString As Object ="http://maps.apple.com/?daddr="& evtUser.Indirizzo & " + " & evtUser.CAP & " + " & evtUser.Citta & " + " & evtUser.Prov
  Main.App.OpenURL(mapString)
  'Main.App.OpenURL($ mapString $)
End if

The device is an iPhone12 with iOS 15.

Thanks in advance for your time
 

Alex_197

Well-Known Member
Licensed User
Longtime User
B4X:
private Sub ShowMap
    
    Try
        
        
        Dim urlMap As String="https://www.google.com/maps/search/"
        Dim su As StringUtils
        Dim Address As String
            
        Address=SelectedClientAddress
        Address=Address.Replace(CRLF," ")
        Address=su.EncodeUrl(Address,"UTF-8")
        urlMap=urlMap & Address
                
        
        Dim App As Application
        
        If App.CanOpenURL(urlMap) Then
            App.OpenURL(urlMap)
        Else
            XUI.MsgboxAsync("Address cannot be shown on a map","HCMS")
        End If
        
    Catch
        Log("ShowMap " & LastException.description)       
    End Try
    
End Sub
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
http://maps.apple.com/?daddr= you need to pass it the coordinates lat, lon
B4X:
Private mainstr As String = "http://maps.apple.com/?daddr=41.916088,12.4618673"
    If (App.CanOpenURL(mainstr)) Then
        App.OpenURL(mainstr)
    End If

if you want to pass an address you have to use the following code:

B4X:
Private mainstr As String = "http://maps.apple.com/?q=Piazza%20Mazzini,Roma"
    If (App.CanOpenURL(mainstr)) Then
        App.OpenURL(mainstr)
    End If

 
Last edited:
Upvote 0

QtechLab

Active Member
Licensed User
Longtime User
Hi Marco, Alex

The issue was the url in bad format. I forgot to replace the blank spaces with %20; and this is very stupid because the entire app that i’m doing works around http requests.

i’m so sorry to have your time for suchmistake.
The url with “?daddr=“ is used to trace a route to the address entered



thanks for your time
Ciao!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…