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

前端 未结 2 1548
感动是毒
感动是毒 2020-12-22 05:28

i am trying to draw polyline for googlemap, it is working fine upto android version 4.4(kitkat) but it is not working in android 5.0(lollipop). what to do for working in lol

2条回答
  •  失恋的感觉
    2020-12-22 06:03

    Try the modified codes for your onPostExecute:

    @Override
    protected void onPostExecute(List>> result) {
            ArrayList points = null;
            //PolylineOptions lineOptions = null;
    
            //MarkerOptions markerOptions = new MarkerOptions();
    
            points = new ArrayList();
    
            // Traversing through all the routes
            for(int i=0;i();
                //lineOptions = new PolylineOptions();              
    
                // Fetching i-th route
                List> path = result.get(i);
    
                // Fetching all the points in i-th route
                for(int j=0;j point = path.get(j);                 
    
                    double lat = Double.parseDouble(point.get("lat"));
                    double lng = Double.parseDouble(point.get("lng"));
                    LatLng position = new LatLng(lat, lng); 
    
                    points.add(position);                       
                }
    
                // Adding all the points in the route to LineOptions
                //lineOptions.addAll(points);
                //lineOptions.width(4);
                //lineOptions.color(Color.BLUE);
    
            }
    
            // Drawing polyline in the Google Map for the i-th route
            //map.addPolyline(lineOptions); 
    
            lineOptions.addAll(points);
            lineOptions.width(4);
            lineOptions.color(Color.BLUE); 
            line = map.addPolyline(lineOptions);
        }           
    

    I moved your list points instance before for loop, and also lineOptions after for loop.

    Hope this help.

提交回复
热议问题