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.