How to stop google MapsActivity from rerouting my route? - android

I am using
String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", sourceLatitude, sourceLongitude, destinationLatitude, destinationLongitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
for providing navigation support in my app , but whenever I go off route than it draws a new route to the destination. How to stop it, I want the route to be fixed

Related

How to show distance between two points on map

I have latitude and longutude of two points. I want to show the route between them by opening google maps from my app on button click. How to do so?
Use below code for getting show route in google map...
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("
http://maps.google.com/maps?" +"saddr=" + sourcelatLng + "&daddr=" + destlatlng;
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
If you want to open maps app with a route from your source to destination, you just need to start an activity with following intent.
Uri routeUri = Uri.parse("http://maps.google.com/maps?saddr=your-lat-1,your-lng-1&daddr=your-lat-2,your-lng-2");
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, routeUri);
startActivity(intent);
Replace your-lat/lng-1/2 with your latitude and longitude.

How to pass a list of coordinates to the default google Map Application?

From my app i am opening the default google map app. Here is how i am doing it.
String uri = String.format(Locale.ENGLISH, "geo:0,0?q=%f,%f(%s)",
locationList.get(1).getLatitude(), locationList.get(1).getLongitude(),"My location");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
Log.i(TAG, "Uri is "+ uri);
this.startActivity(intent);
This is working fine. But is it possible to pass a list of coordinates and plot them all so i could create a path?
Here try this:
String destination = locationList.get(1).getLatitude()+","
+locationList.get(1).getLongitude();
Uri gmmIntentUri = Uri.parse("google.navigation:q="+destination+"&mode=d");
Log.e(TAG,"Intent uri : "+gmmIntentUri.toString());
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mapIntent.setPackage("com.google.android.apps.maps");
this.startActivity(mapIntent);
this will open map in navigation mode from your current location to the specified destination.
you can have a look at the below link to specify way points between your source and destination:
https://developers.google.com/maps/documentation/urls/android-intents
https://developers.google.com/maps/documentation/urls/guide
Let me know if you have any doubts.

how to add my location to google maps api

How to add source address in android for opening google maps with source and destination address?
I have tried the following:
String map ="https://maps.google.com/maps?saddr=My+Location&daddr="+address;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(map));
i.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(i);
I am getting error in map application as "no result for my location"
My requirement is that I want to open google maps application with user current location and destination address which i am passing.
You can try this way:
String uri = String.format(Locale.ENGLISH, "geo:0,0?q=", "ahmedabad");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);

Start Google Map Intent

hi i wanted to make a button which is the button will start google map intent
with my current location and destination location
how to make a google map automaticlly detect my location and destination longitude and lat?
where i put that longi and lat?
i want that map directly draw the direction to destination
final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?"
+ "saddr="+ current_lat+","+current_longi + "&daddr="+dest_address ));
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(intent);
alr tried this code but not working
Try using one of these with the View intent:
geo:latitude,longitude
geo:latitude,longitude?z=zoom
geo:0,0?q=my+street+address
geo:0,0?q=business+near+city
Something like:
Uri uri = Uri.parse(<ONE OF THE ABOVE STRINGS>);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);
Try this one:
String url = "http://maps.google.com/maps?saddr="+currentLattitude+","+currentLongitude+"&daddr="+targetLat+","+targetLang+"&mode=driving";
it should work.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=srcLatitude,srcLongitude&daddr=destLatitude,destLongitude"));
startActivity(intent);
// srcLongitude/Latitude = current Location`s longitude/latitude
// destLongitude/Latitude = Destination Location`s longitude/latitude

It is possible to show a route between two POINTS selecting the type of transport?

I'm showing a route between two points with this code:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+lastLocation.getLatitude()+","+lastLocation.getLongitude()+"&daddr="+(double)point.getLatitudeE6()/1000000+","+(double)point.getLongitudeE6()/1000000));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
This code works perfectly, but I need to add to that code the possibility to select for example, public transport. It is possible?
In your Uri, you can add one more parameter to select type of transport:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+lastLocation.getLatitude()+","+lastLocation.getLongitude()+"&daddr="+(double)point.getLatitudeE6()/1000000+","+(double)point.getLongitudeE6()/1000000 + "&dirflg=r"));
intent.setComponent(new ComponentName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity"));
startActivity(intent);
dirflg = h for driving,
dirflg = r for public transport,
dirflg = w for walking directions.
Transit Mode (public transport) will be displayed only if available for that region, otherwise MapActivity will show a toast for its non-availability and will show directions for driving (motorways).

Categories

Resources