Advertisement
Ankhwatcher

Start navigation

Apr 17th, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1.  @OnClick(R.id.getDirections)
  2.     void getDirections() {
  3.        
  4.         /** Start Navigation in Google Maps **/
  5.         String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?&daddr=%f,%f (%s)", location.geolat, location.geolng, location.name);
  6.         Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
  7.         intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
  8.         try
  9.         {
  10.             startActivity(intent);
  11.         }
  12.         catch(ActivityNotFoundException ex)
  13.         {
  14.             try
  15.             {
  16.                 /** Start navigation in Waze **/
  17.                 uri = "geo: "+location.geolat+","+location.geolng;
  18.                 Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
  19.                 startActivity(unrestrictedIntent);
  20.             }
  21.             catch(ActivityNotFoundException innerEx)
  22.             {
  23.                 Toast.makeText(this, "Please install a maps application", Toast.LENGTH_LONG).show();
  24.             }
  25.         }
  26.  
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement