0

I am trying to draw a polyline between 2 points using Google Maps API v2. It works fine on android KitKat and all the version lower than that. But the polyline is not shown, i.e the route is not shown, when the project is compiled in a phone that has a android version higher than KitKat. Can I know why this is happening? Here is my code

protected void onPostExecute(List<List<HashMap<String, String>>> result) {


        ArrayList<LatLng> points = null;
        //PolylineOptions lineOptions = null;
        MarkerOptions markerOptions = new MarkerOptions();
        String distance = "";
        String duration = "";


        if (result.size() < 1) {
            Toast.makeText(getBaseContext(), "No Points", Toast.LENGTH_SHORT).show();
            return;
        }

        points = new ArrayList<LatLng>();

        // Traversing through all the routes
        for (int i = 0; i < result.size(); i++) {
            //points = new ArrayList<LatLng>();
            // lineOptions = new PolylineOptions();


            // Fetching i-th route
            List<HashMap<String, String>> path = result.get(i);

            // Fetching all the points in i-th route
            for (int j = 0; j < path.size(); j++) {
                HashMap<String, String> point = path.get(j);

                if (j == 0) {    // Get distance from the list
                    distance = (String) point.get("distance");
                    continue;
                } else if (j == 1) { // Get duration from the list
                    duration = (String) point.get("duration");
                    continue;
                }

                double lat = Double.parseDouble(point.get("lat"));
                double lng = Double.parseDouble(point.get("lng"));
                LatLng position = new LatLng(lat, lng);

                points.add(position);
            }



        }
        Toast.makeText(getBaseContext(), distance, Toast.LENGTH_LONG).show();
        tvDistanceDuration.setText(distance);

        // Adding all the points in the route to LineOptions
        lineOptions.addAll(points);
        lineOptions.width(8);
        lineOptions.color(Color.BLUE);
        lineOptions.geodesic(true);

        // Drawing polyline in the Google Map for the i-th route
        line = mMap.addPolyline(lineOptions);
    }

I found only 1 link similar to this question.

google map polyline is not working on android version 5.0(lollipop)

And I've changed my code according to that answer. But that wasnt also successful. Its very confusing as to how something works in a lower API version but not in a higher API version.

Community
  • 1
  • 1
Sadir Omer
  • 48
  • 1
  • 9
  • check this link https://developers.google.com/android/reference/com/google/android/gms/maps/model/Polyline – Prashant Sharma Sep 19 '16 at 06:42
  • thanks, I did. But it still does note work in Android versions above 4.4 – Sadir Omer Sep 19 '16 at 06:52
  • @Sadir Omer . Notice : GooglePlay and GoogleMap should be update . –  Sep 19 '16 at 11:31
  • It is up to date. It works in a Samsung S3 which has android 4.3, but not in a Samsung Note 5 which has Android 6.0.1 and in which the GooglePlay and GoogleMap is up to date. – Sadir Omer Sep 20 '16 at 03:37

0 Answers0