Draw route on map without MapActivity - android

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.

Related

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.

Path between two geopoints on android google maps view

I'm trying to get the path between two geo points on my android app, i don't need any driving directions - just path. What I've already found myself is to draw the straight line between two geopoints (http://djsolid.net/blog/android---draw-a-path-array-of-points-in-mapview). Is it possible to get the actual path? I mean path which I can really walk, road path - not just straight line between two geopoints without parsing the google maps web URL ?
I think the best solution is called android internal map activity to show route between two geo points. Please refer to the code below:
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);
It's called built in map activity and draws a route path between current and fixed latitude and longitude.

How to draw and navigate routes on Google Maps

I want to draw routes on Google Maps (walk or drive), I want to give intent the current user coordinates and the destination coordinates, to draw and navigate the route, as this image
I used this code
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);
but I got "No route found"
Thanks a lot
You can't do that with intent. You should use JSON request with http://maps.googleapis.com/maps/api/directions/output?parameters. If you use JSON request, you must make it like this example, just add your coordinates : String url = "http://maps.googleapis.com/maps/api/directions/json?origin="yourlat","yourlong"&destination="secondlat","secondlong"&sensor=false";
This may help: Android draw route on a Mapview with twoo POI-s and this How do I draw a KML file on a MapView in Android?

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

Draw a route on a map (android)

Can i draw three route in my application(use google map api),i can draw a route with kml,
now i want to draw three different route between two points,such as foot, bike, bus and so
on.
String uri = "http://maps.google.com/maps?saddr=" + lat+","+lon+"&daddr="+lat1+","+lon1;
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);
I think this may help you.
Yes you can draw a route in Android on a map, you may want to start by saving your GPS points into a database.
You could also just use the Google Maps API to do this for you automatically.

Categories

Resources