dynamic Polyline colors with google maps android app

后端 未结 2 1074
感情败类
感情败类 2021-01-26 22:37

I\'m making an app that uses google maps to show when you deviate from a path previously taken. I can show where the deviations occur with a different color, but I have to initi

2条回答
  •  感情败类
    2021-01-26 23:02

    you have to provide a Polylineoptions to addPolyline() to googlemaps object. and to change color of the PolylineOptions you can use color() . or to dynamically change the color of the polyline in googlemaps you can save the line object in a polyline and then use setColor() to change the color of the polyline at any point of code as long as the polyline object is not null.

    to change color of any polyline drawn on google maps or to be drawn you have one method for each of them.

    first case (polylineoptions)

    the polylineoptions is the object that you pass to addpolyline() to draw into the googlemaps. so to change color in this case you have to change it before assigning. using the color() method. but the problem is that once you have changed the color and assigned you can not change it again. to change it again you have to clear the google map and redraw the polyline .

    second case (polyline)

    when you assign a polylineoptions to a googlemaps via the addpolyline() then you can save this object into an polyline. then you can change color of this polyline at any point of time after drawing it on the googlemaps . and this will be easy if you want to change color dynamically after drawing the polyline. the method you will use is setColor().

    i hope this solves your query.

    thank you

提交回复
热议问题