Aditya Gnaneshwar Aditya Gnaneshwar - 11 days ago 7
Android Question

Google Maps Navigation in Android

I am working with Android and building an app that wants to navigate between 2 points. I already have the points with me. I have the route between them as well on google maps. I just want to navigate between them. Could you please help me on this?

Answer

Consider you have two locations source, destination, The below code will redirect you to google navigation, Make it as a method and call when ever you want!.. Let me know if you need any other help

Intent intent = new Intent(Intent.ACTION_VIEW, 

Uri.parse("http://ditu.google.cn/maps?f=d&source=s_d" +
                "&saddr="+source.getLatitude()+
                ","+source.getLongitude()+"&daddr="+
                destination.latitude+
                ","+destination.longitude+
                "&hl=zh&t=m&dirflg=d"));  

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivityForResult(intent, 1);