问题
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