2012-07-17 40 views
0

下面你可以看到,我的代码显示在地图和标记(从JSON):Adsense的使用jQuery UI的地图

$('#map_canvas').gmap().bind('init', function() { 
    $.getJSON('../js/locate.php', function(data) { 
     $.each(data.markers, function(i, marker) { 
      var mapvalue=new google.maps.LatLng(marker.latitude, marker.longitude); 

      $('#map_canvas').gmap('addMarker', { 
       'tags': [''+marker.category+''], 
       'position': mapvalue, 
       'bounds': true,        
       'icon':'../images/'+marker.category+'.png', 
       'animation':google.maps.Animation.DROP 
      }).click(function() { 
       $('#map_canvas').gmap('openInfoWindow', { 'content': ''+marker.category+'<BR><div id="cust_content"></div>' }, this); 
       setTimeout("opencust(\'" +marker.id+"\');",100); 
      });     
     });          
    }); 
}); 

我怎么能在我的地图,新的AdSense脚本:https://developers.google.com/maps/documentation/javascript/advertising#AdvertisingAdUnit

感谢您的帮助!

+0

什么是你想在这里做什么? – insomiac 2012-07-17 02:22:52

+0

我只是想在我的地图上添加AdSense广告。谷歌脚本很容易,但我找不到与jquery-ui-map库一起使用它的方法。 – user1522790 2012-07-17 06:24:36

回答

2

经过一番研究,我使它的工作变化很小。您需要执行以下步骤。

  1. 首先在您的Google Maps JS中包含Adsense。注意添加库=站长&

    <script src="http://maps.google.com/maps/api/js?libraries=adsense&sensor=true"></script> 
    
  2. 修改您的JS如下。通知$( '#map_canvas提供')。GMAP( '得到', '地图')

    $('#map_canvas').gmap().bind('init', function() { 
        $.getJSON('../js/locate.php', function(data) { 
         $.each(data.markers, function(i, marker) { 
          var mapvalue=new google.maps.LatLng(marker.latitude, marker.longitude); 
           $('#map_canvas').gmap('addMarker', { 
           'tags': [''+marker.category+''], 
           'position': mapvalue, 
           'bounds': true, 
           'icon':'../images/'+marker.category+'.png', 
           'animation':google.maps.Animation.DROP 
          }).click(function() { 
           $('#map_canvas').gmap('openInfoWindow', { 'content': ''+marker.category+'<BR><div id="cust_content"></div>' }, this); 
           setTimeout("opencust(\'" +marker.id+"\');",100); 
          }); 
         }); 
        }); 
        var adUnitDiv = document.createElement('div'); 
        var adUnitOptions = { 
         format: google.maps.adsense.AdFormat.HALF_BANNER, 
         position: google.maps.ControlPosition.TOP, 
         backgroundColor: '#c4d4f3', 
         borderColor: '#e5ecf9', 
         titleColor: '#0000cc', 
         textColor: '#000000', 
         urlColor: '#009900', 
         map: $('#map_canvas').gmap('get','map'), 
         visible: true, 
         publisherId: 'YOUR_PUBLISHER_ID' 
        }; 
        adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions); 
    });