Skip to content

Add Google Adsense to Google Maps

apneadiving edited this page May 1, 2012 · 2 revisions

1. Load Adsense Library

<%= gmaps({
          ...
          "map_options" => {"libraries" => ["adsense"] },
          ...
          })
 %>

2. Call Adsense with Javascript

Gmaps.map.callback = function() {
      var adUnitDiv, adUnitOptions;
      adUnitDiv = document.createElement("div");
      adUnitOptions = {
        format: google.maps.adsense.AdFormat.HALF_BANNER,
        position: google.maps.ControlPosition.RIGHT_BOTTOM,
        map: Gmaps.map.serviceObject,
        visible: true,
        publisherId: "ca-pub-3964215240206120"
      };
      new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);
    };

Documentation: http://code.google.com/intl/en/apis/maps/documentation/javascript/advertising.html