简体   繁体   中英

Java Update Markers from a Google Map

I'm trying to build an app that must update a marker every x seconds. Ok I have already accomplished it. Here is the code in my onCreate Method:

 h = new Handler();

        h.postDelayed(new Runnable(){
            public void run(){

                atualizaMapa();

                h.postDelayed(this, delay);
            }
        }, delay);

The problem is: When I'm using the google map and dragging a marker or when a infoWindow is opened, the process get's a little bit lock(x seconds I put) and after it I can drag the marker normally and after 10 seconds it get's lock again...after 10 seconds locked again and again...I've tried everything, but no success. Someone could help me with this problem?

The marker is updated on atualizarMapa(), this method access my webservice and get a json response...

Using postDelayed() method,

causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses . The runnable will be run on the thread to which this handler is attached. The time-base is uptimeMillis(). Time spent in deep sleep will add an additional delay to execution.

On top of that,

When posting or sending to a Handler , you can either allow the item to be processed as soon as the message queue is ready to do so, or specify a delay before it gets processed or absolute time for it to be processed. The latter two allow you to implement timeouts, ticks, and other timing-based behavior.

Method that you used affects the behavior of your app or message scheduling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM