To Fire Up GPS Navigation Automatically

1,775 views
Skip to first unread message

YP Ng

unread,
May 2, 2018, 2:47:34 AM5/2/18
to MIT App Inventor Forum
Dear App Inventor Experts,

May I know how do I fire up the navigation process automatically rather than my user had to press the "Start" Button on the Google Map Navigation each time? They were drivers and is too troublesome for them to each time go and press the "Start" button. Some of them might not be even knowing how to use a 3G phone. Please help.

I had try using different command but still unsuccessful. Instead of "android.intent.action.VIEW" I had tried "android.intent.action.START",or "android.intent.action.RUN".


FireNavigation.aia

SteveJG

unread,
May 2, 2018, 8:52:12 AM5/2/18
to mitappinv...@googlegroups.com
You are using the correct blocks to use ActivityStarter to display Google's Navigate.  The VIEW intent is the correct way to use ActivityStarter.    When you use a navigation solution using the ActivityStarter, your user will have to use the blue START button you circled.  You can provide the information to your user in a Label that they need to use the button ... "When the Navigaton map appears, press the blue START button"   perhaps?
 and

You can use both a current location and a destination location like this:

and it might give you the result you want.    Does it? Edit:   the line in the Action block should be http://maps.google.com/maps?   and the next line should not have the :w in it.

If not, you  have to use a different method to Navigate.  Here are some possibilities:

1) Use the Google Maps Directions API and print out directions (you do not get a map, just directions) https://developers.google.com/maps/documentation/directions/ .. Once you have the directions in JSON format, plot the points you parse from the JSON directions on a Google Static Map https://developers.google.com/maps/documentation/static-maps/intro   You can plot the route waypoints using the  Path points (explained in the Static Map Link).  This is DIFFICULT

2) Do not use Navigate at all.  Use the Static Map API to produce a map between a destination and current location (you get a map but no route) https://developers.google.com/maps/documentation/static-maps/intro.  Search this Forum for   static map   for examples.  Not Difficult but requires a modest amount of block coding.

3) Use the MIT Map component along with  the  router.project-osm.org  API. This experimental api can provide a route in JSON format that you can use in conjunction with the Map Line component.  The link to get the geojson file showing the route waypoints  is     http://router.project-osm.org/route/v1/driving/<startLongitude>,<startLatitude>;<endLongitude>,<endLatitude>?geometries=geojson   where the values within <  > are the actual latitudes and longitudes for the starting and ending locations.  Use the Web component to get the JSON.    This way of plotting routes is DIFFICULT and there is no tutorial for App Inventor.

Regards,
Steve



YP Ng

unread,
May 6, 2018, 9:55:59 PM5/6/18
to MIT App Inventor Forum
I think I found some answer in the web below. Now the problem is how do I incorporate this into the App Inventor block? Anyone has the answer?

Intent intent = new Intent(Intent.ACTION_VIEW, 
    Uri.parse("google.navigation:q=New+York+NY")); 
startActivity(intent);

Chris Ward

unread,
May 6, 2018, 11:35:52 PM5/6/18
to MIT App Inventor Forum
Hello YP

SteveJG's post is using App Inventor's functions to start an Activity - Create a new Project and experiment!

SteveJG

unread,
May 7, 2018, 9:17:31 AM5/7/18
to mitappinv...@googlegroups.com
Hi YP ... using an intent can bring up the Google Navigate app without the need to press the blue START.  Thank you for the idea.

Using App Inventor blocks, there are several possibilities as to how you can code this. The intent requires the + wherever a space is typed for the Destination address. One block example uses the Web>URIEncode component (shown as an active block), another uses a Replace block and one is to hard code the destination (both shown as Disabled blocks).   Any of these methods results in the proper formatting of the intent using the ActivityStarter.DataUri block.  If you use the TextBox to input locations, you can either type an address or geocoordinates.  For example type the coordinates separated by a single space,  38.9072  -77.0369 , and it works as well as typing  Washington D.C.

When using this code snippet, you will discover returning to your App from Google's Navigate is not as simple as pressing the BackButton soft key on your device.  A quick way to return to your app is to press the double rectangle soft key.  That action allows you to look at the active apps on your device, close the Navigate (swipe right) , then click on your App image to restore your main app screen.  There may be other ways (using the BackButton soft key multiple times works and is s l o w )

Good luck with your Project!


Regards,
Steve
ASNavigate.aia

YP Ng

unread,
May 7, 2018, 9:32:04 PM5/7/18
to MIT App Inventor Forum
SteveJG,

Brilliant! You have gave me the exact answer which I'm searching for all the while in the internet. Now I can continue with my project without any problem. You are the man. I will mark as completed and give you whatever credit you want. Big thank to Steve who give me answer others cannot give. Thank you Captain America :)


Reply all
Reply to author
Forward
0 new messages