Multi color Polyline in google map v2 in android

前端 未结 3 1720
长发绾君心
长发绾君心 2021-01-21 03:35

I searched a lot i didn\'t find any proper solution for it.Help and link could be appreciated :-)

3条回答
  •  后悔当初
    2021-01-21 04:07

    maybe its so late !!! but i solve this problem and want put it for some people. maybe useful. and for detail i solve it by new polylineOption every 5 Latlng in map

     private static void animateMarker(final GoogleMap map, final Marker marker, final List directionPoint,
                                      final boolean hideMarker, final List degree, final List colors) {
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final long duration = 300000;
        final PolylineOptions[] polylineOptions = {new PolylineOptions()};
        final Interpolator interpolator = new LinearInterpolator();
        if (map != null) {
            handler.post(new Runnable() {
                int i = 0;
    
                @Override
                public void run() {
                    long elapsed = SystemClock.uptimeMillis() - start;
                    float t = interpolator.getInterpolation((float) elapsed / duration);
    
                    if (i < directionPoint.size() - 1) {
    
                        final LatLng currentPosition = new LatLng(
                                directionPoint.get(i).latitude * (1 - t) + directionPoint.get(i + 1).latitude * t,
                                directionPoint.get(i).longitude * (1 - t) + directionPoint.get(i + 1).longitude * t);
    
                        marker.setRotation(degree.get(i));
                        marker.setPosition(currentPosition);
                        polylineOptions[0].add(directionPoint.get(i)).color(colors.get(i));
                        map.addPolyline(polylineOptions[0]);
                        if (i % 5 != 0) {
                            polylineOptions[0] = new PolylineOptions();
                            polylineOptions[0].add(directionPoint.get(i)).color(colors.get(i));
                            map.addPolyline(polylineOptions[0]);
                        }
                        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLng(currentPosition);
                        map.animateCamera(cameraUpdate);
                        i++;
    
                    }
                    if (t < 1.0) {
                        // Post again 100ms later.
                        handler.postDelayed(this, 100);
                    } else {
                        if (hideMarker) {
                            marker.setVisible(false);
                        } else {
                            marker.setVisible(true);
                        }
                    }
                }
            });
    
        }
    }
    

    Ok it's my screenshot , color will be change by changing speed of car

提交回复
热议问题