Search code examples
androidgoogle-mapsandroid-intentdirection

error launching direction between user location and destination


I am trying to create destination between user location and destination. The destination coordinates are passed from previous activity (which has listview). Everything is going well but somehow the destination shows no result but only lat/lng:(50.798844, -1.0889845) are shown. I know i am missing some bits to make this work. Can anyone helpme.

Thanks

this is how i get my intent

Bundle intent = getIntent().getExtras();

        if (intent !=null){
       int position = intent.getInt("position", 0);

          final LatLng  latlng = intent.getParcelable("log");

directions:

Intent intent1 = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://maps.google.com/maps?saddr="+"&daddr="+latlng));

        // intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       startActivity(intent1);}
        });

Solution

  • The problem is due to the toString() function.

    toString() returns lat/lng:(50.798844, -1.0889845) rather than 50.798844, -1.0889845.

    That being said, you should do it in this way:

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://maps.google.com/maps?saddr="+"&daddr="+latlng.latitude+","+latlng.longitude));