Overlay with Google Maps API v3 not reappearing after hide

孤者浪人 提交于 2019-12-13 04:43:30

问题


I read a lot of examples. They all mention to hide the overlay by

overlay.setMap(null);

That works fine. But showing it again after hiding it before does not work although it will be shown during initialization. All examples tell me to use

overlay.setMap(map);

But the overlay does not reappear ?! What is wrong?

See my code at http://jsbin.com/oworor/3/edit

MJ


回答1:


The "map" variable is local to the mapInitialize function, change:

        function mapInitialize() {
            var myLatlng = new google.maps.LatLng(47.72, 13.48);
            var myOptions = {
                zoom: 13,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.TERRAIN
            }
            var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

to:

        function mapInitialize() {
            var myLatlng = new google.maps.LatLng(47.72, 13.48);
            var myOptions = {
                zoom: 13,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.TERRAIN
            }
            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);


来源:https://stackoverflow.com/questions/11450560/overlay-with-google-maps-api-v3-not-reappearing-after-hide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!