Как сделать направление Google Maps с помощью Android? - PullRequest
1 голос
/ 14 сентября 2011

Поддерживает ли надстройка API Карт Google для Android SDK функции маршрутизации (направления) на картах Google. Если нет, есть ли хороший метод, который будет использоваться при реализации инструкции для карт Google на Android

Пакет DrivingDirection (com.google.googlenav.DrivingDirection) удален с Android SDK 1.1.

1 Ответ

0 голосов
/ 14 сентября 2011

, чтобы получить маршруты проезда от src до места назначения.

используйте следующий метод для получения направления движения в arrayList

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