Monday, August 15, 2016

Google Maps JS v3 API - unable to display multiple Google maps on the same page

If the maps are coming out as blank gray, then you will probably have to use such a function:


window.maps = new Array();


function refresh_maps() {


    setTimeout(function () {


        var lenx = window.maps.length;

        for (var i = 0; i < lenx; i++) {

            var cur_map = window.maps[i];

            google.maps.event.trigger(cur_map, 'resize');

            cur_map.setCenter(cur_map.xxcenter);


       
        }

        //alert("DONE");

    }, 1000);


}


It refreshes all the Google Maps by raising a resize event. Also, it's important to re-center them.

The looping which adds maps to the array can look like this:

..............


        map.xxcenter = myLatlng;


        window.maps.push(map);
...........

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...