admob positioning problem

   Warning: sorry for my English. Didnt find admob forum in plugins section, so ask here.

Here the problem - I successfully integrate admob into my app, but i cant position it well for different android devices.

My config.lua

application = { content = { width = 780, height = 1024, scale = "zoomEven", fps = 60, }, }

Yes, I use zoomEven , cause dont like any croping.

Here my build.setting

-- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight settings = { orientation = { default = "portrait", supported = { "portrait", } }, iphone = { plist = { UIStatusBarHidden = false, UIPrerenderedIcon = true, -- set to false for "shine" overlay --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend --[[-- iOS app URL schemes: CFBundleURLTypes = { { CFBundleURLSchemes = { "fbXXXXXXXXXXXXXX", -- example scheme for facebook "coronasdkapp", -- example second scheme } } } --]] } }, -- Android permissions androidPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", "android.permission.READ\_PHONE\_STATE", }, plugins = { -- key is the name passed to Lua's 'require()' ["CoronaProvider.ads.admob"] = { -- required publisherId = "com.coronalabs", }, }, }

For this app I want banner ad in the bottom of the screen. I read somewhere, that corona supports only smart banners for admob. 

From here https://developers.google.com/mobile-ads-sdk/docs/admob/smart-banners  I learn that there are only 50 and 90 pixel heights for portait orientered apps for any android device. 90 for tablets and 50 for others. 

So, for correct positioning, I need to know if the device is a tablet or phone, then convert my config pixels into real ones.

ads.show( "banner", { x = display.screenOriginX , y = display.screenOriginY + display.viewableContentHeight - adsDy } )

Where adsDy - height of banner in real size. To get it i use next code:

local adsDy = 0 if system.getInfo( "androidDisplayWidthInInches" ) then if( system.getInfo( "androidDisplayWidthInInches" ) \> 5 or system.getInfo( "androidDisplayHeightInInches" ) \> 5 ) then --is a tablet adsDy = 90 else adsDy = 50 end adsDy = adsDy \* ( display.viewableContentHeight / (system.getInfo("androidDisplayYDpi") \* system.getInfo( "androidDisplayHeightInInches" )) ) end

(system.getInfo(“androidDisplayYDpi”) * system.getInfo( “androidDisplayHeightInInches” ))  - this must return the real pixel height of device. But for my asus tpad 300 it returns 1232 instead of 1280. Or it doesnt count the navigation bar and it’s 48 pix in height?

Anyway, with this way I can get good positioning on Asus TPad 300 and it begins from left side of screen, but it’s a little wider than the screen. But Galaxy SIV shows it very bad:

vpngF.jpg

It seems about 33% of real height of banner and 80% of its width.

I try to solve this case 2 days but have no idea yet. Searching on corona forums doesnt give a result also.

I would be glad to hear any ideas and solutions!

lets up it

Hi @sparrowdrunken,

In your screenshot, is the banner ad the grey+lime thing on the button, where I can see “FRE” on the right side?

If I understand the issue, your content area is bleeding off the side edges on one of these devices, because you use ZoomEven? That is probably why the ad is larger than the screen in some cases.

You may want to approach the positioning differently, instead of using the “DPI” and “InInches” fetching info. I believe that the nav bar space is “not always” regarded on Android devices, which leads to unpredictable results.

I know this isn’t a “solution” in itself, but perhaps you can calculate the positioning without using the system.getInfo APIs, and instead base it off the content area.

Out of curiosity, what are the values returned when you simply print these to the Terminal/console?

[lua]

print( display.screenOriginX )

print( display.screenOriginY )

[/lua]

Thanks,

Brent

lets up it

Hi @sparrowdrunken,

In your screenshot, is the banner ad the grey+lime thing on the button, where I can see “FRE” on the right side?

If I understand the issue, your content area is bleeding off the side edges on one of these devices, because you use ZoomEven? That is probably why the ad is larger than the screen in some cases.

You may want to approach the positioning differently, instead of using the “DPI” and “InInches” fetching info. I believe that the nav bar space is “not always” regarded on Android devices, which leads to unpredictable results.

I know this isn’t a “solution” in itself, but perhaps you can calculate the positioning without using the system.getInfo APIs, and instead base it off the content area.

Out of curiosity, what are the values returned when you simply print these to the Terminal/console?

[lua]

print( display.screenOriginX )

print( display.screenOriginY )

[/lua]

Thanks,

Brent

Have the same problem, positioning the ad at the bottom of the screen (portrait orientation).

Guess lots of you use admob and position the banner at the bottom.

Anyone would be so kind to share his solution ?

Regards,

Damir.

Yep, same issue here, for iAds I could figure it out, for for some reason on Android nothing seems to be working.

@juan.csdc, what ad module are you using for Android.  iAds is for iOS/Apple only.

Hi Rob, 

Sorry for the confusion, I use iAds for apple devices and admob for android devices.

For iAds was very easy to place it on the bottom because it’s reference point seems to be LeftBottom instead of TopBottom.

To calculate the height for iOS I’m using the following code:

local scaleY = 1/display.contentScaleY if string.sub(system.getInfo("model"),1,4) == "iPad" then fxAds.bannerHeight = 50\*scaleY else fxAds.bannerHeight = 66\*scaleY end

While for Android and Admob:
 

local scaleY = 1/display.contentScaleY fxAds.bannerHeight = 50\*scaleY

I’ve tried different alternatives for calculating the bannerHeight for Android but any of them seems to be working.

I just used the adMob sample app, added my AppID, changed it from interstitial to banner, changed the positioning code to:

showAd = function( adType )         local adX, adY = display.screenOriginX, display.contentHeight - 50         statusText.text = ""         ads.show( adType, { x=adX, y=adY } ) end

And the ad is anchored to the bottom of the screen as I would expect.  It appears to be similar to a “TopLeft” reference point.   You’re doing some unusual scaling and I don’t know if that’s impacting you or not.  Ad’s are not really “display” objects, but more like native.newWebViews() in how they behave.

I’m using the lastest config.lua published here

--calculate the aspect ratio of the device local aspectRatio = display.pixelHeight / display.pixelWidth application = { content = { width = aspectRatio \> 1.5 and 800 or math.ceil( 1200 / aspectRatio ), height = aspectRatio \< 1.5 and 1200 or math.ceil( 800 \* aspectRatio ), scale = "letterBox", fps = 30, imageSuffix = { ["@2x"] = 1.3, }, }, }

Hi Rob,

thank you very much trying to solve this but unfortunately your solution does not work (at least for me).

On the Samsung Tab 2 and Transformer tablets the banner is a bit to low (bottom of ad is cut-off), on the Xperia phone the banner is to high.

Config.lua:

application = {
    content = {
        width = 640,
        height = 960,
        scale = “letterBox”,
        fps = 60,
        launchPad = false,

    },
}

Using latest public release 1202.

Regards,

Damir.

@juan.csdc I’m using the same config.lua, but I’m not using the same content scale.   I suspect it has to do with the fact that your content area is over twice as big and you have to adjust accordingly.  After some experimentation this worked for me with 800 and 1200

        local adX, adY = 0, display.contentHeight - 125

This comes from:  800 / 320 = 2.5 * 50px high ad = 125 total scaled height. Now this put the box a touch high.  It’s not flush to the bottom, but it’s in same place the sample app had it at 320x480 screens size (just a little space below).  Using 120 instead of 125 made it flush, but I suspect the ad itself may be a little short and the 125 is the right amount (and it mathematically works out)

Damir, in our case, you are using a content area that is an aspect ratio of 1:1.5, which will fill the screen on an iPhone 4.  It does not fill the screen on 16:9 type devices like the Xperia (1:1.7778), so that screen is longer than your content area.  The Samsung is a 1024x600 device or a 1:1.70 It’s shorter than the Xperia.  You config.lua needs to adapt to your device.  Given your config.lua you’re going to have to calculate what your real screen height is which will be something like:

adY = (display.content.pixelHeight / content.pixelWidth * disiplay.contentWidth) / 320 * 50

or something similar.

Thank you Rob.

Is support for “normal” banners for admob planned ?

(one of my games needs 320x50 banner in landscape)

If I got it right, Corona has implemented only smart-banners and those always fill the whole screen width.

Regards,

Damir.

I’m not sure.  Your best bet is to goto http://feedback.coronalabs.com and put in a feature request for it.

Thanks Rob,

I’ll try what you have mentioned before. Those same calculations will apply for apple right? So instead of using the scaleY I should be using the math you explained before?

Potentially.  Probably.

Hi Rob,

I finally got it working nicely on my android devices and my iPad mini, unfortunately I couldn’t test it on an iphone 4 and 5, but I’ve tried it also with a few Android devices, here it’s the code of my ads class for any “config.lua” (maybe)

if( not \_G.fx.ads ) then \_G.fx.ads = {height = 0} end local fxAds = \_G.fx.ads ads = require "ads"; local function fxAdListener(event) table.dump(event) end function fxAds.init() -- Load Corona 'ads' library if fx.device.isApple then if fx.device.isTablet then fxAds.bannerHeight = display.contentWidth / 320 \* 50 else fxAds.bannerHeight = display.contentWidth / 320 \* 66 end -- The name of the ad provider. local adNetwork = "iads"; local appID = appInfo.ads.iAds; ads.init(adNetwork, appID, fxAdListener); elseif fx.device.isAndroid then if fx.device.isTablet then fxAds.bannerHeight = display.contentWidth / 320 \* 90 else fxAds.bannerHeight = display.contentWidth / 320 \* 50 end -- The name of the ad provider. local adNetwork = "admob"; local appID = appInfo.ads.adMob; ads.init(adNetwork, appID, fxAdListener); end end function fxAds.showBanner(x, y, params) if fx.device.isSimulator then if params.srpH == "bottom" then y = y - fxAds.bannerHeight end fxAds.adBox = display.newRect(x, y, w, fxAds.bannerHeight) fxAds.adBox:setFillColor(255, 0, 0) elseif fx.device.isApple then ads.show("banner", {x=x, y=y, testMode=false}); elseif fx.device.isAndroid then if params.srpH == "bottom" then y = y - fxAds.bannerHeight end ads.show("banner", {x=x, y=y, testMode=false}); end end function fxAds.hide() ads.hide() end fxAds.init()

Take in consideration that I’m using this code from a part of a larger framework I’m currently developing so there are a few variables that are self explanatory, but that those are not calculated here.
I’m planning to release this framework to all developers as soon as I finish with the basics.

Hope this can helpful for others =)

Have the same problem, positioning the ad at the bottom of the screen (portrait orientation).

Guess lots of you use admob and position the banner at the bottom.

Anyone would be so kind to share his solution ?

Regards,

Damir.

Yep, same issue here, for iAds I could figure it out, for for some reason on Android nothing seems to be working.