Android Question How to initialize Google Maps app intent with destination address in car navigation mode

toby

Well-Known Member
Licensed User
Longtime User
I would like to launch Google Maps app from my app so that Google Maps is in car navigation mode, ready for user to tap Start button for the audio navigation turn by turn guide travelling from Point A to Point B. I tried with the following code:
B4X:
Dim intent1 As Intent
    Dim uri1 As Uri 'depends on ContentResolver
    Dim lat1, lat2, lng1, lng2 As Float
    
    'Point A: double tree by Hilton New York Downtown hotel
    lat1=40.7039969273062
    lng1= -74.01234432667555
    
    'Point B: Wall Street Subway station:
    lat2=40.706404373426096
    lng2=-74.00946363419844
    
    
    uri1.parse($"http://maps.google.com/maps?saddr=${lat1},${lng1}&daddr=${lat2},${lng2}"$)
    intent1.Initialize(intent1.ACTION_VIEW,uri1)
    'intent1.SetComponent("googlemaps")
    StartActivity(intent1) 'this line cause errors:


And I got this Error: android.content.ActivityNotFoundException

** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 50 (Main)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=(StringUri) http://maps.google.com/maps?saddr=40.704,-74.012344&daddr=40.706406,-74.00946 flg=0x20000 pkg=com.google.android.apps.maps }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1943)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1617)
at android.app.Activity.startActivityForResult(Activity.java:4513)
at android.app.Activity.startActivityForResult(Activity.java:4471)
at android.app.Activity.startActivity(Activity.java:4832)
at android.app.Activity.startActivity(Activity.java:4800)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:857)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at b4a.example.main.afterFirstLayout(main.java:111)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:169)
at android.app.ActivityThread.main(ActivityThread.java:6578)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Could someone kindly show me how to fix it, please?

TIA
 

DonManfred

Expert
Licensed User
Longtime User
I do it this way in my app.

B4X:
    Dim mapIntent As Intent
    Dim geouri As String

    geouri = "google.navigation:q=" & lblkdAdresse.Text
    mapIntent.Initialize(mapIntent.ACTION_VIEW,geouri)
    'mapIntent.SetComponent("googlemaps")
    mapIntent.WrapAsIntentChooser("Bitte App auswählen")
    StartActivity(mapIntent)
lblkdAdresse is a label with the customeraddress (street, town)
 
Upvote 0

Alain75

Member
Hi,
In order to launch google maps to search for a location, the intent is :

Google maps search:
    Dim strt As Intent
    strt.Initialize(strt.ACTION_VIEW,"geo:0,0?q=search location...")
    StartActivity(strt)

And all the references of google maps intents are here
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…