17

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".

chiarfe
  • 522
  • 3
  • 15
  • If you click on marker of map, it should go to google navigation? or you want to draw routes from current location? – Shadow Aug 08 '13 at 09:26
  • I want my application to setup directly using intent call the map to display the route from current location to the fixed location, so that the user doesn't need to setup navigation by himself – chiarfe Aug 08 '13 at 10:43

5 Answers5

19

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).

Geobits
  • 22,218
  • 6
  • 59
  • 103
  • This is very useful. If you want to use a start address other than your own location, modify the url as `"http://maps.google.com/maps?saddr=hamburg&daddr=berlin"`. Also works in browser(at least in Chrome). – Kerem Nov 25 '14 at 23:00
4

in above post

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

It will ask you for source address it will not automatically pass your source address you need to select it on map by taping,

You can use GPS for that purpose... after getting the LatLng coordinates you can pass them to url...but it should be in f=a not f=d..

https://maps.google.com/maps?f=a@saddr=LatLng&daddr=badlapur

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Amit Modak
  • 169
  • 3
  • 8
2

I just used this and it opened straight to google maps in navigation mode from my current location to the address specified in the text variable. text should be in the same format as you would type it in the search bar your self

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("google.navigation:q="+text));
startActivity(intent);
Anonymous
  • 4,470
  • 3
  • 36
  • 67
0

please make url like this

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

but make one more thing clear

in manifiest file: use a INTERNET PERMISSION

otherwise it will crash

0

Try this:

"https://www.google.com/maps/dir//41.3951982,-72.855568/41.279386,-72.825098"

You can have multiple locations, but starting location will be current location.

asok Buzz
  • 1,876
  • 3
  • 24
  • 50