加载后谷歌地图发出ajax请求

时间:2015-12-01 04:55:17

标签: javascript jquery ajax google-maps

有没有办法知道谷歌地图是否已加载?我需要在加载地图后发出一个ajax请求

目前我在带有信息窗口的地图中显示一组用户。但问题是由于浏览器卡住了太多数据。

    var infowindow;
    var markersLongLat = {$markersLongLat};
    var geocoder = new google.maps.Geocoder();
    var markerImg = '{$markerImg}';

        function initialize() {
        if(hasFilter == 1){
        var zoom = 2;
        var myLatlng = new google.maps.LatLng(0, 0);
        if('' != markersLongLat){
        var myLatlng = new google.maps.LatLng(markersLongLat[0].lat, markersLongLat[0].long);
        var zoom = 5;
        }
        var myOptions = {
            zoom: zoom,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        }
        else{
        var myLatlng = new google.maps.LatLng(0, 0);
        var myOptions = {
            zoom: 2,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        }
        map = new google.maps.Map(document.getElementById('googleMap'), myOptions);
        console.log('map loaded successfully');

        // Adding longLat markers
        if ('' != markersLongLat) {
        console.log('markersLongLat');
        for (var x = 0; x < markersLongLat.length; x++) {                 var person =  new Object();
            person.id = markersLongLat[x].id
            person.name = markersLongLat[x].name
            person.lat = markersLongLat[x].lat
            person.long = markersLongLat[x].long
            person.address = markersLongLat[x].address

           codeLongLat(person);
      }
       }




     function codeLongLat(markersLongLat) {
        var lat = markersLongLat.lat;
        var long = markersLongLat.long;
        var name = markersLongLat.name;
        var info = markersLongLat.info;
        var markerObj = new MarkerWithLabel({
              map: map,
              position: new google.maps.LatLng(lat, long),
              title: name,
              labelContent: name,
              labelClass: 'marker-labels',
              icon:markerImg
         });

          google.maps.event.addListener(markerObj, 'click', function() {
          if (infowindow) infowindow.close();
          infowindow = new google.maps.InfoWindow({content: info});
          infowindow.open(map, markerObj);
          });
     }

    google.maps.event.addDomListener(window, 'load', initialize);

1 个答案:

答案 0 :(得分:1)

我认为你正在寻找这个......

google.maps.event.addListenerOnce(map, 'idle', function(){
    //loadedFully
});

了解更多this question