1

所以这是我的代码

<script type="text/javascript">

var gmarkers= [];
var amarkers=[];
var map;
function HideAllMarkers() {
    if(amarkers.length>0){
    for (var i = 0; i < amarkers.length; i++) {
        amarkers[i].setMap(map);

    }}
    document.getElementById('ff').className="friends";
        document.getElementById('alll').className="all select1";
 }

function ShowAllMarkers() {
    if(amarkers.length>0){
    for (var i = 0; i < amarkers.length; i++) {
        amarkers[i].setMap(null);

    }}
    document.getElementById('ff').className="all select1";
        document.getElementById('alll').className="friends";
}

function initialize() { 


var styles = [
  { featureType: "all",
    stylers: [
    { hue: "#c86f4c" },
    { lightness : 20},
    { saturation: -100}
  ]
},{
  featureType: "road",
  elementType: "geometry",
  stylers: [
    { lightness: 100 },
    { visibility: "simplified" }
  ]
},{
  featureType: "road",
  elementType: "labels",
  stylers: [
    { visibility: "off" }
  ]
}
];

var infoboxOptions = {
         content: ''
        ,disableAutoPan: false
        ,maxWidth: 140
        ,pixelOffset: new google.maps.Size(-1, -50)
        ,zIndex: 1000
        ,closeBoxMargin: "1px 1px 1px 1px"
      ,infoBoxClearance: new google.maps.Size(1,1)
        ,isHidden: false
        ,pane: "floatPane"
        ,enableEventPropagation: false
    };  

  var styledMap = new google.maps.StyledMapType(styles,
 {name: "Sample"});
map = new google.maps.Map(document.getElementById("mapbg"),
{        
center: new google.maps.LatLng(28.6232, 77.2118),        
zoom: 12,
scrollwheel: true, 
streetViewControl: true,
scrollwheel: true,
scaleControl: true,
navigationControl: true,
mapTypeControlOptions: {
  mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
}    
}); 
var ib = new InfoBox(infoboxOptions); 
 var locations = [
      ["name 1", 28.6139, 77.2089 , "./cache/570570949.png" , "array1" ,     "570570949", "http://profile-a.xx.fbcdn.net/hprofile-    ash4/203005_570570949_1413033020_q.jpg" , "New Delhi, India", 1],
        ["name 2", 28.47, 77.03 , "./cache/661010614.png" , "array1" , "661010614",     "http://profile.ak.fbcdn.net/hprofile-ak-prn1/49964_661010614_67481594_q.jpg" , "Gurgaon,     Haryana", 1],

 var allcations = [
  ["Ankush Arora", 18.5203, 73.8567 , "./cache/1348211929.png" , "array2" ,     "1348211929", "https://fbcdn-profile-a.akamaihd.net/hprofile-a ash4/371624_1348211929_10156158_q.jpg" , "Pune, Maharashtra" , 1],
        ["Ashish Singhal", ,  , "./cache/729961674.png" , "array2" , "729961674", "http://profile.ak.fbcdn.net/hprofile-ak-prn1/50098_729961674_762622_q.jpg" , "" , 0]
   ];
  var marker, i;

var bounds = new google.maps.LatLngBounds ();
  for (i = 0; i < locations.length; i++) { 


    var lat=locations[i][1];
    var lng=locations[i][2];
    lat += parseFloat(((Math.floor(Math.random() * 200) - 99) / 5000).toString() + locations[i][5]);
 lng += parseFloat(((Math.floor(Math.random() * 200) - 99) / 5000).toString() + locations[i][5]);
    var lutlun = new google.maps.LatLng(lat, lng);
    if(locations[i][8]===1)
    {
    if(lat>0 || lat<0)
    {
        if(lng>0 || lng<0)
        {
            bounds.extend (lutlun);
        }
    }
    }
  marker = new google.maps.Marker({
    position: lutlun,
    map: map,
    optimized: false,
    icon: locations[i][3],
    photo_url:locations[i][6],
    cloc: locations[i][7],
    content: locations[i][0],
    cid: locations[i][5],
    crel : locations[i][4]
  });
    gmarkers.push(marker);
map.fitBounds (bounds);
google.maps.event.addListener(marker, 'mouseover', (function(marker, i) {
    return function() {
          ib.hide();
      ib.show();
      ib.setContent(document.getElementById('ibbb1'));
              ib.open(map, marker);
     // marker.setZIndex(9999);


 }
  })(marker, i));


google.maps.event.addListener(marker, 'mouseout', function () {
    //  marker.setZIndex(1);                                                    
window.t = setTimeout(function () {
    ib.hide()
}, 2000);
});
google.maps.event.addListener(ib, 'domready', function () {
$('#ibbb1').on('mouseenter', function () {
    clearTimeout(t);
}).on('mouseleave', function () {
        ib.hide();

})
});


  }
 for (i = 0; i < allcations.length; i++) { 



    var lat=allcations[i][1];
    var lng=allcations[i][2];
    lat += parseFloat(((Math.floor(Math.random() * 200) - 99) / 5000).toString() + allcations[i][5]);
  lng += parseFloat(((Math.floor(Math.random() * 200) - 99) / 5000).toString() + allcations[i][5]);
    var lutlun = new google.maps.LatLng(lat, lng);
    if(allcations[i][8]===1)
    {
    if(lat>0 || lat<0)
    {
        if(lng>0 || lng<0)
        {
            bounds.extend (lutlun);
        }
    }
    }
  marker = new google.maps.Marker({
    position: lutlun,
    map: null,
    optimized: false,
    icon: allcations[i][3],
    photo_url:allcations[i][6],
    cloc: allcations[i][7],
    content: allcations[i][0],
    cid: allcations[i][5],
    crel : allcations[i][4]
   });
    amarkers.push(marker);
   if(amarkers.length>0){ map.fitBounds (bounds);}
google.maps.event.addListener(marker, 'mouseover', (function(marker, i) {
    return function() {

    var ib5=document.getElementById('ibbb5');
    ib5.innerHTML='<img src="images/place_small_icon.png" width="12" height="16" alt="place"> '+ marker.cloc + '</p>';
          ib.hide();
      ib.show();
      ib.setContent(document.getElementById('ibbb1'));
      ib.open(map, marker);
    //marker.setZIndex(9999);



 }
  })(marker, i));


google.maps.event.addListener(marker, 'mouseout', function //() {
    window.t = setTimeout(function () {
    ib.hide()
    }, 2000);
});

google.maps.event.addListener(ib, 'domready', function () {
$('#ibbb1').on('mouseenter', function () {
    clearTimeout(t);
}).on('mouseleave', function () {
        ib.hide();

})
});  

}

 map.mapTypes.set('map_style', styledMap);
  map.setMapTypeId('map_style');  
}
google.maps.event.addDomListener(window, 'load', initialize);

</script>

一切都很好,除了信息框 mouseenter 和 mouse leave 事件不起作用......

任何人都可以建议我哪里出错了..还有其他方法还是有一些语法错误...调试js很痛苦thanx

4

0 回答 0