google map intent not animate to current location in android app...? - android

I have an android application in which one place I want to call maps.google.com intent and display direction from source to destination.
But when I use this, I want maps animate to direction path automatically.
I use below for calling maps intent
String saddr = "current location";
String daddr = "other location";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+ saddr+ "&daddr="+ daddr));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
intent call properly and show me maps, and draw path as well but not animate to that place.

Check this link out:
http://developer.android.com/guide/appendix/g-app-intents.html
In your:
Uri.parse("http://maps.google.com/maps?saddr="+ saddr+ "&daddr="+ daddr)
try:
Uri.parse("http://maps.google.com/maps?saddr="+ saddr+ "&daddr="+ daddr+"&z=10")

Related

Open map to show direction from current location through intent-Android

I have many latitude longitude in my android app. I want to know how to open a chooser or Google map App through intent and show direction from current location to that latitude and longitude.Like i have lat=28.605989,lon=77.372970 and my current location is somewhere so when i click on button in my app these lat lon pass through intent and will show direction from my current location to these lat lon. Thank you.
To navigate user to destination lat long, we can use something like this
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?daddr=28.605989,77.372970"));
startActivity(intent);
Here . we are passing just destination lat long daddr=28.605989,77.372970, so by default, your current location will be source location.
To add extra information with your url .
String my_data= String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=20.5666,45.345(My Destination Place)");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(my_data));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
You can send intent to Google Map android application by following code:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=22.458,34.34&daddr=75.124,35.448"));
startActivity(intent);
In the above URI saddr represents the source address i.e. your current location and daddr represents the coordinates of the destination location.

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

Intent to Google Navigation for itinerary with several waypoints

I want to know, if it's possible to put several "checkpoints" within "Google Navigation" (Google Maps Navigation) With a query that follows the next syntax : "google.navigation:q=44.871709,-0.505704...."
If it possible, what is the syntax for separate two points ?
For one point it works, example : "google.navigation:q=44.871709,-0.505704"
But I would put a few checkpoints for example :
LatLng point1 = new LatLng(44.871709,-0.505704);
LatLng point2 = new LatLng(43.572665,3.871447);
Intent(android.content.Intent.ACTION_VIEW,Uri.parse("google.navigation:q="+
point1.latitude+","+point1.longitude+";"+ point2.latitude+","+point2.longitude));
I read others issues, they say to use this syntax :
"http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447"
With above solution, "Google Navigation" is not started automatically, we must choose one application "Google Maps" and next, to click on Itinerary (in top of the screen) to start "Google Navigation".
I would like to avoid it if possible.
Here is a way to supress the dialog and go to maps directly.
String uri = "http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Let me know if you still have issues.
UPDATE
As of May 2017, there is a better approach, the Google Maps URLs API
https://developers.google.com/maps/documentation/urls/guide
Using this API you can construct an URL with origin, destination and waypoints and pass it to the intent
String uri = "https://www.google.com/maps/dir/?api=1&origin=Madrid,Spain&destination=Barcelona,Spain&waypoints=Zaragoza,Spain%7CHuesca,Spain&travelmode=driving&dir_action=navigate";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Check these 2 methods, both of them work properly for me.
METHOD 1:
String packageName = "com.google.android.apps.maps";
String query = "google.navigation:q=49.4839509,8.4903999";
Intent intent = this.getPackageManager().getLaunchIntentForPackage(packageName);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(query));
startActivity(intent);
METHOD 2:
String packageName = "com.google.android.apps.maps";
String query = "google.navigation:q=49.4839509,8.4903999";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(query));
intent.setPackage(packageName);
startActivity(intent);
Because point1.longitude is Double,you should use this
String.valueOf(point1.latitude);
Intent(android.content.Intent.ACTION_VIEW,Uri.parse("google.navigation:q="+String.valueOf(point1.latitude)+","+String.valueOf(point1.longitude)+";"+String.valueOf( point2.latitude)+","+String.valueOf(point2.longitude)));
Or you can use this,but it is just the same.
point1.toString().replace("lat/lng: (", "").replace(")", "")
point1.toString() the result is "lat/lng: (44.871709,-0.505704)",remove the "lat/lng: (" and ")".
then you can get the result that you want.
Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+point1.toString().replace("lat/lng: (", "").replace(")", "")+"&daddr="+point2.toString().replace("lat/lng: (", "").replace(")", "")));
Or you can try this
Uri uri = Uri.parse("http://maps.google.com/mapssaddr="+point1.toString().replace("lat/lng: (", "").replace(")", "")+"&daddr="+point2.toString().replace("lat/lng: (", "").replace(")", ""));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
I hope this can help you.
You have to just pass destination location. Google Maps app will automatically take your current location for navigation.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + String.valueOf(destination latitude)
+ "," + String.valueOf(destination longitude)));
startActivity(intent);

Categories

Resources