javascript - Google Maps V3 StreetView not displaying on second setVisible() call -
edit: heard google, they've confirmed issue on end.
edit2: contact @ google has informed me they've fixed bug.
i've got troublesome bug using google maps v3 api.
if set map, switch streetview, close streetview, reopen, imagery appears blank (though controls still display). if click on controls move camera, imagery returns.
what causes this? can see code below simple, can't think i've gone wrong.
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > <head> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> </head> <body> <div id="map" style="width:500px;height:300px"></div> <script type="text/javascript"> var map = new google.maps.map(document.getelementbyid('map'), { center: new google.maps.latlng(37.767063, -122.445724), maptypeid: google.maps.maptypeid.roadmap, zoom: 15 }); var streetview = map.getstreetview(); streetview.setposition(map.getcenter()); settimeout(function() { streetview.setvisible(true); }, 1500); settimeout(function() { streetview.setvisible(false); }, 3000); settimeout(function() { streetview.setvisible(true); }, 4500); </script> </body> </html>
i found same annoying bug , developed workaround further div , bit of css. assign streetview #street
<div id="map" style="width:500px;height:300px;display:block"></div> <div id="street" style="width:500px;height:300px;display:none"></div>
add function toggle visibility of divs:
function togglestreetview() { var mapdiv = document.getelementbyid('map'); var streetdiv = document.getelementbyid('street'); var streetvisible = (streetdiv.style.display == 'block'); if (streetvisible) { // hide streetview, show map streetdiv.display = 'none'; mapdiv.display = 'block'; } else { // vice versa mapdiv.display = 'none'; streetdiv.display = 'block'; streetview.setvisible(true); /* order important, show after div visible */ } }
maybe not elegant solution - works. css absolute positioning , javascript framework, prefer jquery, can add nice fade effect.
Comments
Post a Comment