【问题标题】:Adsense with jquery-ui-mapAdsense 与 jquery-ui-map
【发布时间】:2013-09-08 20:39:15
【问题描述】:

您可以在下面看到我的显示地图和标记的代码(来自 Json):

$('#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

感谢您的帮助!

【问题讨论】:

  • 你想在这里做什么?
  • 我只是想在我的地图上添加一个 AdSense 广告。使用谷歌脚本很容易,但我找不到将它与 jquery-ui-map 库一起使用的方法。

标签: jquery google-maps adsense


【解决方案1】:

经过一番研究后,我做了一些改动就让它工作了。您需要执行以下步骤。

  1. 首先在您的 Google Maps JS 中包含 Adsense。注意添加了 libraries=adsense&

    <script src="http://maps.google.com/maps/api/js?libraries=adsense&sensor=true"></script>
    
  2. 如下修改你的 JS。注意 $('#map_canvas').gmap('get','map')

    $('#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);
    });
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-05
    • 2014-04-18
    • 2012-10-07
    • 1970-01-01
    • 2015-01-21
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    相关资源
    最近更新 更多