Question

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

Was it helpful?

Solution

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

OTHER TIPS

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

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

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top