Android and draw routes in Google maps - android

I have a small problem, I need to develop an application that shows the route of public transport, I found tutorials about route of cars.
I saw this example:http://maps.google.com/maps?f=d&hl=en&saddr=25.04202,121.534761&daddr=25.05202,121.554761&ie=UTF8&0&om=0&output=kml
and tried to add dirflg = & rB the URL to show the public transport but server responded with the empty kml.
Does anyone know how to help me?

assuming that you are asking this for android, you can use the following intent
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345")); startActivity(intent);
where saddr and daddr are starting and destination address's location coordinates.
same has been discussed in several threads already

Related

set From location to current location in google maps android programmatically

I am creating an app where it requires opening google maps to navigate to a place in walking mode and to set source/from location to current location.
Here is the code I use.
String url = "https://maps.google.co.in/maps?q=" + destination + "&mode=walking";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
How do I set "From location" to "current location"??
Thanks.
I would suggest using a Google Maps URLs instead of the link you provided in the example. The Google Maps URLs is an official and recommended way to launch Google Maps app on mobile devices and web browsers.
Please note that if you omit the origin parameter in the Google Maps URLs, the API will use your current location if available
origin: Defines the starting point from which to display directions. Defaults to most relevant starting location, such as user location, if available. If none, the resulting map may provide a blank form to allow a user to enter the origin. The value can be either a place name, address, or comma-separated latitude/longitude coordinates. A string should be URL-escaped.
So, you should rewrite your code as
String url = "https://www.google.com/maps/dir/?api=1&destination=" + destination + "&travelmode=walking&dir_action=navigate";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
I hope this helps!

How to open the shortest path of google map navigation in android?

I'm opening a google map using my android program. I did it with the following URL,
http://maps.google.com/maps? saddr=31.186371,121.489885&daddr=31.249351,121.45905&mode=driving
But this opens a view like,
I want to open the shortest path(1st one in list view) from these paths. Is there a way to do this? How may I do this?
According to the documentation, you can launch the turn by turn navigation by this intent:
google.navigation:q=a+street+address
you can use these code to launch the intent:
Uri gmmIntentUri = Uri.parse("google.navigation:q=Taronga+Zoo,+Sydney+Australia");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
As you might able to tell, this can only give a turn-by-turn direction from current location to point A, but not point A to point B. You should consider using the web direction API and draw the polyline on your own Google Maps to gain more controls.

Draw route on map without MapActivity

I want to draw a path on map between known points(lat, long) using:
String uri = "http://maps.google.com/maps?f=d&hl=en&saddr="+source_latitude+","+source_longitude+"&daddr="+destination_latitude+","+destination_longitude;
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);
But instead of just drawing route, Google Maps shows menu Car/Bus/By foot, trying to make a route from my current location to those points. What am I doing wrong? Is it still possible to draw route on map using the method above?
By running this intent you are basically opening an "outside" application - Google Maps that is not related to your application. the behavior you are receiving is the behavior that should be for the version of Google Maps you have in your phone. You can't edit the way it behaves, only the things that you are allowed to change using the settings screen of this application.
You have to parse the xml or json that your are using in the url in an Asynctask class and draw it on the map.

google GetDirection in Android

I have used this following code for getting route for two directions but i need to implement multiple destination options in android like GetDirections.
Even i tried the method of drawline() functionality also but it will not show the route instructions like (turn left,right, etc.,).
please can any one help me for code the route path or to embed the feature of waypoints listed link below
https://google-developers.appspot.com/maps/documentation/javascript/examples/directions-waypoints
Code
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=st.%20louis,mo&daddr=washington,dc%20to:chicago,il%20to:new%20york,ny");
startActivity(intent);

Google maps paths

I want to set paths on a Google maps. I’ve done some coding and able to draw single paths on a Google map. I want to know if there is any method to accomplish my objective. How can I do this?
want to show multiple paths between two Geo coordinators.
I’m new to this and can you please help me to do this. Thank you.
try this
String uri = "http://maps.google.com/maps?saddr=" + (srcLocation.getLatitude())+","+(srcLocation.getLongitude())+"&daddr="+destLat+","+destLon;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
Draw route using this. This is for one route.

Categories

Resources