开发者

Google maps js api v3: grey map in chrome

Im having some problems with a street view map: http://server.patrikelfstrom.se/johan/fysiosteo/?page_id=118

Sometimes the window gets grey instead of showing the streetview. So my question is; Is there any way to know when the map has finished loading? I guess its treying to render the map before its completly loaded? Thanks

 function initialize() {

      var myLatlng = new google.maps.LatLng(57.6988062, 11.9683293);
      var myOptions = {
        zoom: 16,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        disableDefaultUI: true
      }
      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

       var marker = new google.maps.Marker({
          position: myLatlng, 
          map: map, 
          animation: google.maps.Animation.DROP,
          title:"Fysiosteo"
      });   

      var panoramaOptions = {
          position: myLatlng,
          addressControl: false, 
           pov: {
            heading: 90,
            pitch: 0,
            zoom: 0
          } 
        };

        var panorama = new  google.maps.StreetViewPanorama(document.getElementById("pano"),panoramaOptions);
        map.setStreetView(panorama);  



        google.maps.event.addListener(panorama, 'idle', function() { console.log('done'); });

    }

    function loadScript() {
      var script = document.createElement("script");
      script.type = "text/javascript";
      script.src = "h开发者_运维技巧ttp://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize";
      document.body.appendChild(script);


    }

    window.onload = loadScript;

I tried with this code to print "done" to the console when the map has finished loading, but it didnt work. Am i doing it wrong? :)


The answer to your specific question ("Is there any way to know when the map has finished loading?") is: Yes. When a Map object is finished loading, it will trigger an idle event. Documentation of events that a Map object fires can be found at http://code.google.com/apis/maps/documentation/javascript/reference.html#Map.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜