Reputation: 46
I am using this URL
http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f
to show the direction page between two points. and I want to know what can I add to this URL to get the route between two points.
Currently it is showing direction page first and when I press route tab so it shows route page but what I want is it directly should go to route page.
I am using this code
String new_url = "http://maps.google.com/maps?saddr=" + ServerData.LATTITUDE + "," + ServerData.LONGITUDE + "&daddr=" + latitude + "," + longitude ;
Intent intent_map = new Intent(Intent.ACTION_VIEW, Uri.parse(new_url));
startActivity(intent_map);
Please Help
Upvotes: 1
Views: 4183
Reputation: 8362
You can do the same by opening default Android Maps Activity in Android.
You can have a look to this sample code :
E.g URL :- `
https://maps.google.com/maps?saddr=28.61000000,77.23000000&daddr=28.98000000,77.02000000
String uri = "http://maps.google.com/maps?saddr=" + currentLatitude+","+currentLongitude+"&daddr="+destLatitude+","+destLongitude;
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);
Screenshot Attached
Upvotes: 2
Reputation: 5333
Android Supports Accessing Internal Application and its best solution called android internal map activity to show route between two geo points . Please refer below 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);
It called built in map activity and draw a route path between current and fixed latitude and longitude.
Upvotes: 0
Reputation: 6037
Try with below code. The below code will return list of latitude and longitude positions. From that you have to draw line for nearest points using canvas. The below code also have list of place markers string you can make use of that.
private ArrayList<String> getDirectionData(String srcPlace, String destPlace) {
String urlString = "http://maps.google.com/maps?f=d&hl=en&saddr="
+ srcPlace + "&daddr=" + destPlace
+ "&ie=UTF8&0&om=0&output=kml";
Log.d("URL", urlString);
Document doc = null;
HttpURLConnection urlConnection = null;
URL url = null;
ArrayList<String> pathConent = new ArrayList<String>();
try {
url = new URL(urlString.toString());
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(urlConnection.getInputStream());
} catch (Exception e) {
}
NodeList nl = doc.getElementsByTagName("LineString");
for (int s = 0; s < nl.getLength(); s++) {
Node rootNode = nl.item(s);
NodeList configItems = rootNode.getChildNodes();
for (int x = 0; x < configItems.getLength(); x++) {
Node lineStringNode = configItems.item(x);
NodeList path = lineStringNode.getChildNodes();
pathConent.add(path.item(0).getNodeValue());
}
}
placeMarks=new ArrayList<String>();
NodeList place=doc.getElementsByTagName("Placemark");
for(int i=0;i<place.getLength();i++){
Node root=place.item(i);
NodeList config=root.getChildNodes();
Node placenode=config.item(0);
NodeList name=placenode.getChildNodes();
placeMarks.add(name.item(0).getNodeValue());
Log.i("Node Value: ", ""+name.item(0).getNodeValue());
}
placeMarks.remove((placeMarks.size()-1));
Log.i("LineString: ", pathConent.get(0));
ArrayList<String> tmpcoords=new ArrayList<String>();
for(int i=0;i<pathConent.size();i++){
tmpcoords.addAll(Arrays.asList(pathConent.get(i).split(" ")));
}
//String[] tempContent = pathConent.split(" ");
return tmpcoords;
}
Upvotes: 2