2

I have an app that displays a map with a marker. When the user touches the marker I want to start navigation for them.

Is there an Intent/Activity that I can pass a longitude and latitude and start theusers navigation app?

Thanks for any help.

Kara
  • 6,115
  • 16
  • 50
  • 57
LilMoke
  • 3,176
  • 7
  • 48
  • 88

3 Answers3

6

I solved it like this. The url posted is similar.

Intent navigation = new Intent(
            Intent.ACTION_VIEW,
            Uri.parse("http://maps.google.com/maps?saddr=START_LAT,START_LON&daddr=END_LAT,END_LON"));
startActivity(navigation);

Where Start is the START_LON and START_LAT is the longitude and latitude and END_LON, END_LAT is the end

Calvin
  • 617
  • 1
  • 12
  • 34
LilMoke
  • 3,176
  • 7
  • 48
  • 88
1

That works fine:

    googleMap.setMyLocationEnabled(true);

    LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria cri = new Criteria();
    bestProvider = locManager.getBestProvider(cri, true);

    Location loc = locManager.getLastKnownLocation(bestProvider);
    String latMy = String.valueOf(loc.getLatitude());
    String lngMy = String.valueOf(loc.getLongitude());

    Toast.makeText(this, "Navigation", Toast.LENGTH_SHORT).show();
    String url = "http://maps.google.com/maps?saddr=" + latMy + ","
            + lngMy + "&daddr=" + "18.7703500,19.4534500";

    Intent navigation = new Intent(Intent.ACTION_VIEW);
    navigation.setData(Uri.parse(url));

    startActivity(navigation);
Serafins
  • 1,237
  • 1
  • 17
  • 36
1

Use :

Uri gmmIntentUri = Uri.parse("google.navigation:q="+"18.7703500,19.4534500");
                Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
                mapIntent.setPackage("com.google.android.apps.maps");
                startActivity(mapIntent);
Renjith Krishnan
  • 2,446
  • 5
  • 29
  • 53