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.
Related
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
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).
https://developers.google.com/maps/documentation/android/lines doc says by making the ".geodesic(true)" option, it will follow the curvature of the earth. But it just shows a straight line. Any suggestions?
try this code
String uri = "http://maps.google.com/maps?saddr=" +
currentLatitude+","+currentLongitude+"&daddr="+fixedLatitude+","+fixedLongitude;
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);
this might be help you
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")
I want to open an inbuilt google map intent to show route between two place without open a complete action dialog, which asked for Browser and Map .
I tried this.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+PreferenceData.getLatitude(HotelInfomation.this)+","+PreferenceData.getLongitude(HotelInfomation.this)+"&daddr="+latitude+","+longitude));
startActivity(intent);
But it opens a dialog asking Complete Action Using Browser or map . I don't want that Dialog .
without open a complete action dialog, which asked for Browser and Map
In this case you need to tell android which application you want to use to display map.
Here you go
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+PreferenceData.getLatitude(HotelInfomation.this)+","+PreferenceData.getLongitude(HotelInfomation.this)+"&daddr="+latitude+","+longitude));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Intent intent = new Intent(
android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="
+ Data.map_latitude + ","
+ Data.map_longitude + "+&daddr="
+ Data.infoLatitude + ","
+ Data.infoLogitute + ""));