I searched a lot i didn't find any proper solution for it.Help and link could be appreciated :-)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Try this -
@Override
public void onMapReady(GoogleMap map) {
// Add a thin red line from A to B.
Polyline line1 = map.addPolyline(new PolylineOptions()
.add(new LatLng(40.1, -74.2), new LatLng(40.7, -74.0))
.width(5)
.color(Color.RED));
and then another line from B to C with a different color and so on
Polyline line2 = map.addPolyline(new PolylineOptions()
.add(new LatLng(40.7, -74.0), new LatLng(41.3, -74.5))
.width(5)
.color(Color.GREEN));
....
Note that getMapAsync() is the new preferred way to get the map object. https://developers.google.com/maps/documentation/android-api/map
Polyline details here - https://developers.google.com/android/reference/com/google/android/gms/maps/model/Polyline
回答2:
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<LatLng> directionPoint,
final boolean hideMarker, final List<Float> degree, final List<Integer> 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