javascript - show streetview in infowindow -
i'm trying streetview show in infowindow. had working in v2 api method (settimeout) did not work me in v3, trying use addlistener method show panorama. error getting null reference when try pass div wish show streetview in. found couple of questions on here seemed on point don't see doing differntly - both examples used infowindow domready event using also. here code.
var map; function initialize() { var lat = document.getelementbyid("lat").value; var lon = document.getelementbyid("lon").value; var latlon = new google.maps.latlng(parsefloat(lat), parsefloat(lon)); var mapoptions = { center: latlon, zoom: 15, streetviewcontrol: false, maptypeid: google.maps.maptypeid.roadmap }; map = new google.maps.map(document.getelementbyid("map-canvas"), mapoptions); var sv = new google.maps.streetviewservice(); sv.getpanoramabylocation(latlon, 50, showshopinfo); } function showshopinfo(panodata, status) { var streetview; var dirname = document.getelementbyid("directory").value; var zipsearch = document.getelementbyid("zipcodesearch").value; var valid = document.getelementbyid("shopvalid").value; var shopinfo; if(status == google.maps.streetviewstatus.ok) { // got street view! streetview = true; shopinfo = "<div id='shopinfo'><table border='0'><tr><td height='200'>"; shopinfo = shopinfo + "<div id='svmini' style='height: 200px; width: 200px;'></div></td></tr>"; shopinfo = shopinfo + "<tr><td><br /><b><a href='shopprofilebu.asp?validationid=" + valid + "&directoryname=" + dirname + "&zipcodesearch=" + zipsearch + "' title='shop profile'>"; shopinfo = shopinfo + document.getelementbyid("shopname").value + "</b><br /></a>"; shopinfo = shopinfo + document.getelementbyid("address").value + "<br />"; shopinfo = shopinfo + document.getelementbyid("city").value + ", "; shopinfo = shopinfo + document.getelementbyid("state").value + " "; shopinfo = shopinfo + document.getelementbyid("zipcode").value + "<br /><br />"; shopinfo = shopinfo + "<b>" + document.getelementbyid("phone").value + "</b></td></tr></table></div>"; } else { // no street view available streetview = false; shopinfo = "<br /><b><a href='shopprofilebu.asp?validationid=" + valid + "&directoryname=" + dirname + "&zipcodesearch=" + zipsearch + "' title='shop profile'>"; shopinfo = shopinfo + document.getelementbyid("shopname").value + "</b><br /></a>"; shopinfo = shopinfo + document.getelementbyid("address").value + "<br />"; shopinfo = shopinfo + document.getelementbyid("city").value + ", "; shopinfo = shopinfo + document.getelementbyid("state").value + " "; shopinfo = shopinfo + document.getelementbyid("zipcode").value + "<br /><br />"; shopinfo = shopinfo + "<b>" + document.getelementbyid("phone").value + "</b>"; } var infowindow = new google.maps.infowindow({ content: shopinfo, position: map.getcenter() }); infowindow.open(map); if(streetview) google.maps.event.addlistener(infowindow, 'domready', showpanomini(panodata.location.latlng.lat(), panodata.location.latlng.lng())); } function showpanomini(plat, plon) { var panolat = parsefloat(document.getelementbyid("panolat").value); var panolon = parsefloat(document.getelementbyid("panolon").value); var panoyaw = parsefloat(document.getelementbyid("panoyaw").value); var panopitch = parsefloat(document.getelementbyid("panopitch").value); var panozoom = parsefloat(document.getelementbyid("panozoom").value); var panolatlon; if(panolat==0 && panolon==0) panolatlon = new google.maps.latlng(plat, plon); else panolatlon = new google.maps.latlng(parsefloat(panolat), parsefloat(panolon)); var panopov = { heading: parsefloat(panoyaw), pitch: parsefloat(panopitch) }; var panooptions = { position: panolatlon, pov: panopov, addresscontrol: false, linkscontrol: false, zoomcontroloptions: { style: google.maps.zoomcontrolstyle.small }, visible: true }; var panorama = new google.maps.streetviewpanorama(document.getelementbyid("svmini"), panooptions); } google.maps.event.adddomlistener(window, 'load', initialize);
this function using in v2 display streetview.
settimeout(showpanomini(plat, plon), 1000);
eta: took time look, solved problem myself. reason, making callback parameter listener infowindow anonymous function works, while making regular function not. here fixed portion works:
google.maps.event.addlistener(infowindow, 'domready', function() { var panolat = parsefloat(document.getelementbyid("panolat").value); var panolon = parsefloat(document.getelementbyid("panolon").value); var panoyaw = parsefloat(document.getelementbyid("panoyaw").value); var panopitch = parsefloat(document.getelementbyid("panopitch").value); var panozoom = parsefloat(document.getelementbyid("panozoom").value); var panolatlon; if(panolat==0 && panolon==0) panolatlon = panodata.location.latlng; else panolatlon = new google.maps.latlng(parsefloat(panolat), parsefloat(panolon)); var panopov = { heading: parsefloat(panoyaw), pitch: parsefloat(panopitch) }; var panooptions = { position: panolatlon, pov: panopov, addresscontrol: false, linkscontrol: false, zoomcontroloptions: { style: google.maps.zoomcontrolstyle.small }, visible: true }; var panorama = new google.maps.streetviewpanorama(document.getelementbyid("svmini"), panooptions); });
Comments
Post a Comment