我正在使用这个网址

http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f


显示两点之间的方向页。
我想知道我可以添加到此URL以获得两点之间的路线。

当前它首先显示方向页,当我按路线选项卡时它显示路线页,但是我要直接直接转到路线页。

我正在使用此代码

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


请帮忙

最佳答案

尝试下面的代码。以下代码将返回纬度和经度位置列表。由此,您必须使用画布绘制最接近点的线。以下代码还提供了可以使用的位置标记字符串列表。

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

07-26 00:05
查看更多