Why does Traffic Layer always use cache?

I made an application that displays Google maps using the Traffic Layer. The problem is that it always shows the level of traffic in the cache, so it is absolutely useless. I need a cache for other things.

How can I prevent the use of the traffic layer using the cache without completely disconnecting it from the application?

+4
source share
1 answer

As I already answered here , it seems that there is no legal way to update the level of traffic, even on maps.google.com it isn’t auto-delivered. But I found a dirty hack that makes the work work - manually updating the tile image:

function reloadTiles() {
    var tiles = $("#map-canvas").find("img");
    for (var i = 0; i < tiles.length; i++) {
        var src = $(tiles[i]).attr("src");
        if (/googleapis.com\/vt\?pb=/.test(src)) {              
            var new_src = src.split("&ts")[0] + '&ts=' + (new Date()).getTime();
            $(tiles[i]).attr("src", new_src);                                                   
        }               
    }
} 
+4
source

Source: https://habr.com/ru/post/1536823/


All Articles