Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open android native google maps app obtaining directions starting from current position

I'm trying to open google maps from my application, setting a route from the phone current position to a fixed position. I'm using this code:

String uri = "https://maps.google.com/maps?saddr=&daddr=example";        
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);

The problem is that I don't know what to put in saddr= to reference my current position. I've found many other questions like this but no answer worked (such as leaving saddr= empty or saddr=Current, they don't work).

I don't want to use native android locator, I just want to know if there's a way to ask google maps "start from my current position".

like image 679
chiarfe Avatar asked Aug 08 '13 09:08

chiarfe


1 Answers

You can explicitly to it to open in direction mode with an f=d parameter. With that set and no start address, it should use the device's current location. So more like this:

"https://maps.google.com/maps?f=d&daddr=berlin"

Note: This doesn't work in a browser; it opens the directions page with a blank field for start. Used in an intent sent to the native maps application, it works correctly(at least on my 4.2.2 gNex).

like image 97
Geobits Avatar answered Oct 11 '22 14:10

Geobits