1

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

Fan-Droid
  • 46
  • 1
  • 6
  • check this question: [How to display a route between two geocoords in google maps? (Android)](http://stackoverflow.com/questions/2643993/how-to-display-a-route-between-two-geocoords-in-google-maps-android) – Paresh Mayani Nov 25 '11 at 08:43
  • 1
    Check this answer of Max Gontar: [J2ME/Android/BlackBerry - driving directions, route between two locations](http://stackoverflow.com/questions/2023669/j2me-android-blackberry-driving-directions-route-between-two-locations/2023685#2023685) – Paresh Mayani Nov 25 '11 at 08:45
  • can i pass multiple lat and long in this kml url ?just example via some points – Girish Patel Jan 09 '12 at 06:42

3 Answers3

2

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 enter image description here

Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
2

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;
    }
ilango j
  • 5,967
  • 2
  • 28
  • 25
0

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.

sravan
  • 5,303
  • 1
  • 31
  • 33