How to enable google map navigation in android app
Asked Answered
R

4

9

I have two points on google map first one is the source and second is the destination, I have the route between these points on the map.Now I want to navigate user from source to destination as Google does on Google Map Like this:-enter image description here

Reformatory answered 24/6, 2017 at 7:33 Comment(1)
did you find any solution?Leech
P
12

The Google Maps Android API v2 doesn't provide any functionality for navigation. It is in contradiction with Terms of Service of Maps APIs. Have a look at section 10.4 c (iii) of ToS:

No navigation. You will not use the Service or Content for or in connection with (a) real-time navigation or route guidance; or (b) automatic or autonomous vehicle control.

https://developers.google.com/maps/terms#section_10_4

If you need navigation you should create an intent that opens the Google Maps app in navigation mode. There is a Google Maps URLs that allows to construct a universal, cross-platform URL to launch Google Maps intents from your application. You can open navigation mode of native app following this documentation:

https://developers.google.com/maps/documentation/urls/guide#directions-action

Hope this helps!

Panne answered 26/6, 2017 at 11:57 Comment(3)
Nice answer but if that's the case, how does uber and ola show in-app navigation?Laxation
They use Navigation SDK that requires separate license and I suspect it's expensive. This SDK was mentioned in I/0 2018: youtu.be/XVjyIA3f_Ic?t=21m8sPanne
@Laxation Any progress?Prig
P
3

There is a way to stimulate a view like that but not embedded like uber but very close.

 public void loadNavigationView(String lat,String lng){
    Uri navigation = Uri.parse("google.navigation:q="+lat+","+lng+"");
    Intent navigationIntent = new Intent(Intent.ACTION_VIEW, navigation);
    navigationIntent.setPackage("com.google.android.apps.maps");
    startActivity(navigationIntent);
}

You call the method and provide the latitude and longitude.It will launch Google map navigation.Like uber

Pinkiepinkish answered 1/3, 2019 at 20:20 Comment(1)
Hello, where is this documented? I would like to add several stopsZettazeugma
F
1

After searching, I found something on this context. Now google providing In-app Navigation and Google Maps turn-by-turn directions support. It's paid, you can check more about this on below link.

https://cloud.google.com/maps-platform/rides-and-deliveries

Not sure if it solve your problem or not.

Feminacy answered 7/4, 2021 at 13:2 Comment(0)
P
0

This is how you can open and enable Google Map Navigation

  private fun startNavigation(lat: Double, lng: Double) {
    val uri = Uri.parse("google.navigation:q=" + lat + "," + lng + "&mode=d")
    //create an intent
    val mapIntent = Intent()

    //add action & data
    mapIntent.action = Intent.ACTION_VIEW
    mapIntent.data = uri

    //package name for google maps app
    mapIntent.setPackage("com.google.android.apps.maps")
    try {
        requireContext().startActivity(mapIntent)
    } catch (e: ActivityNotFoundException) {

        //if map app isn't resolved/installed catch error
        e.printStackTrace()
    }
}
Plymouth answered 21/8, 2024 at 21:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.