Вопрос:

Can we use web services google direction api in android? If so how can I show the polypoints in a map?

android maps android-maps

30 просмотра

1 ответ

176 Репутация автора

How can I show the poly points on android maps? This is the sample JSON which I get from the direction API. I want to draw overview_polyline on android maps. As android maps polyline adds by using LatLng.

Here is the sample JSON https://codebeautify.org/jsonviewer/cb8d34d5

Автор: Sai Krishna Источник Размещён: 08.11.2017 10:34

Ответы (1)


1 плюс

176 Репутация автора

Reference - http://javapapers.com/android/draw-path-on-google-maps-android-api/

private List<LatLng> decodePoly(String encoded) {

        List<LatLng> poly = new ArrayList<LatLng>();
        int index = 0, len = encoded.length();
        int lat = 0, lng = 0;

        while (index < len) {
            int b, shift = 0, result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lat += dlat;

            shift = 0;
            result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lng += dlng;

            LatLng p = new LatLng((((double) lat / 1E5)),
                    (((double) lng / 1E5)));
            poly.add(p);
        }
        return poly;
    }
Автор: Sai Krishna Размещён: 08.11.2017 11:14
Вопросы из категории :
32x32