Draw a route on a map (android) - 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.

Related

How to add marker to a specific location in Google Maps in Android Studio?

I have created a button which takes the user to a specific location on Google Maps. Here is the snippet:
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
However, the Map merely zooms to the particular location without adding a marker to the co-ordinates I have put. Can someone please help me?
Thank You.
This works for me (the 'hellothere' is a label you can replace or remove):
String uri = String.format(Locale.ENGLISH, "geo:0,0?q=%f,%f(hellothere)",latitude,longitude);
UPDATE: the geo: parameter can be 0,0 when supplying a location query.
(When testing you may want to close the Map app each test particularly if not moving the marker.)

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.

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