admob.height()

Type Function
Return value Number
Revision 2017.3060
Keywords ads, advertising, AdMob, height
See also admob.show()
admob.*

Overview

Only applies to banner ads. Gets the height of a pre-loaded banner ad in content coordinates. This function is convenient if you need to get the height of the banner before showing it for fine-tuned positioning.

If the device is rotated, you must load a new banner and then call this function again to get the correct height value in anticipation of showing it within the new device orientation.

Syntax

admob.height()

Example

local admob = require( "plugin.admob" )

-- Declare variable for storing banner height; this may change if device is rotated
local bannerHeight

-- AdMob listener function
local function adListener( event )

    if ( event.phase == "init" ) then  -- Successful initialization
        -- Load an AdMob banner ad
        admob.load( "banner", { adUnitId="YOUR_ADMOB_AD_UNIT_ID" } )
        
    elseif ( event.phase == "loaded" ) then
        if ( event.type == "banner" ) then  -- Banner ad is loaded
            bannerHeight = admob.height()  -- Get the loaded banner's height
            -- Show the banner ad with a 30 pixel gap between the screen bottom
            admob.show( "banner", { y = display.actualContentHeight - bannerHeight - 30 } )
        end
    end
end

-- Initialize the AdMob plugin
admob.init( adListener, { appId="YOUR_ADMOB_APP_ID" } )