last day (14 days later) » 

2:47 PM
0
Q: Visualize progress on GoogleMaps Android

XverhelstXI'm creating a small test application to visualise my progress on a Google Map using the Google Maps Android API. (API: Here) My backend serves me data about the polylines between two given coordinates. The Android application decodes the data and draw the polylines on the GoogleMaps view. I'...

 
how do you "recolor" polylines? I'm sure it works because i've code in my apps that enable users to change the color of the polylines
 
I tried using setColor on the Polyline and color on the PolylineOptions. But none seem to work. What did you use? Do you need to reinvalidate the map or something?
 
nope. color on polylineOptions works only Before drawing the polyline, setColor on polyline instead works on an object already added to the map and kept as variable (you did not put that code, so I can't understand if you do it correctly). In my code I just take the polyline I want to recolor and do: myPolyline.setColor(Color.RED) or similar
 
I've updated my code above: drawPolyline(). This code is called in onResume and draws the polyline on the map. A route guidance is received from the server which contains routeparts. These routeparts exists out of polylineoptions which are decoded with MapUtils.
 
ok so here 1- If you call it in onResume, you should clear the map before adding new polylines, because it can be already plines before the onPause. 2-You have to set the color of polyline options in decodePolyLines method. 3- What is isFinishing() ? is it true?
 
2:47 PM
If onPause is called, does it remove or clear the map itself? After opening the application, pausing it (onpause) and the onresume, the map is cleared. Does something happen internally when pausing?
 
Usually not, it depends on how you develop the app. If the fragment is retained not all the shapes are removed. To be sure that this is done, call a map.clear() before adding all your data.
 
What version of GMS do you use?
I'm working on an (existing) project for a client and he uses 5.0.
 
oh i have used these methods since last year (july 2014 and I don't remember the version) but it works also on the actual 7.5.
Why you can't clear the map before drawing? Do the setWidth method work instead?
 
How exactly are you redrawing (your progress) on a map
I'll check the setWidth method now
So what happens: OnResume clears the map and initializes it. Then i'm drawing the polylines, markers, etc afterwards
the drawing is done with the code on stack overflow
then on every location change i check the closest distance between me and the polylines
and if there is a match (distance smaller then 5m or something) i want to color the polygon
How exactly are you redrawing (your progress) on a map?
 
my redraw is just a polyline.setColor()
in my app, the user click a button and the polyline changes color, and the code is just polyline.setColor
in your question there is no code about the color
 
3:02 PM
i just tried setWidth and this seems to work ..
private void updatePolylines() {

if (polyLinesOptions != null && !isFinishing()) {

//Find the closest polyline to our current location
int index = findClosestPolyline(polyLines);

if (index > -1) {

//Update the polyline.
// Dynamically updating a polyline is impossible, first we need to
// remove the polyline, change the color and add the new one.

Polyline lastPolyline = polyLines.get(index);

lastPolyline.setColor(Color.GRAY);
lastPolyline.setWidth(25);

Log.i("NavigationActivity", "Coloring last polyline with index: " + index);
 
yes, exactly
 
width works for me
but the color doesn't
i guess there is a bug using setColor
in version 5.0.0
i'll try updating my version and let you know
 
try yo update your version, but try also to put the color in another way.
The documentation says ARGB color, and Color class should be ok, but try to specify color in argb
this is black 0xff000000
 
3:27 PM
OKay thanks
i think i found my problem
apparently the user who wrote the code before me
drew 2 polyines over each other
an i tried to adapt the one below everytime..
that why i didn't see it changing
 
3:40 PM
oh good you found the problem!
 
3:54 PM
Thanks mate
i you write a small answer i'll accept it
:)
 

last day (14 days later) »