Android Question Scaling the map image inside WebView obtained from the static map API

Lakhtin_V

Active Member
Licensed User
Longtime User
I successfully get the part of the map I need. But this drawing is always larger than the width of the screen.
WebView scaling:
Public MapViewer As WebView

                MapViewer.Initialize("")
                Activity.AddView(MapViewer, 2%x, 1%y, 96%x, 54%y)
                MapViewer.LoadUrl(Starter.mapURL)
It turns out that the requested map size of 450x450 does not decrease in width on a smartphone with a resolution of 1920x1080. I tried on different smartphones, the picture always received in reality is about 30% -50% larger than the screen width, why. How can I fit the received card into a rectangle on the smartphone screen.
 

drgottjr

Expert
Licensed User
Longtime User
webview will fit the image as desired. do you know html code?
there are a number of way to achieve the scaling.

you could also use an image view. the scaling would then be
achieved using b4a code.

if you must use a webview, b4a code can only control the frame
that holds the webview; you need either html or javascript to handle
scaling within the webview itself. you can write html and/or
javascript in b4a code and pass it to webview, but the webview
does the actual scaling. there is a rendering engine inside webview
that draws the page. you need to tell it what you want it to do.
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
how could the look code for filling the picture map in image frame. Perhaps then I will have more opportunities to fit the map into image view then use webview.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
resizing (or scaling) a bitmap is a solution to a particular problem,
but it can have unpleasant side effects. before resizing, you need
to take into account the dimensions of the bitmap and of the image
view and think about what the result will look like. a large bitmap
greatly reduced or a small bitmap greatly enlarged are unpleasant
to look at.

there are 3 ways to proceed:
1) decide on size of image view and (possibly) resize images to fit.
or
2) use image size to create an image view of that size.
or
3) load a bitmap "sample" to fit a given image view.

these links refer to bitmap scaling
original method:
https://www.b4x.com/android/forum/threads/loadbitmap-loadbitmapresize-loadbitmapsample.82693/

latest:
https://www.b4x.com/android/forum/threads/b4x-b4ximageview-imageview-resize-modes.121359/#content

i am more familiar with the original method, so to fit a large image on your device's screen,
an example might be:
B4X:
dim iv as imageview
iv.initialize("iv")
activity.addview(iv,0%x,0%y,100%x,100%y)    ' image view fills the screen
iv.bitmap = loadbitmapresize(file.dirassets,"bitmap.png",iv.width,iv.height,true)

this assumes 2 things:
1) you want to use the full screen to display the bitmap
2) the bitmap is already stored on your device.

if you are downloading a bitmap (eg, with okhttputils2), then when you download the bitmap
(dim downloadedbitmap as bitmap = httpjob.getbitmap), just resize it:
iv.bitmap = downloadedbit.resize(iv.width,iv.height,true)

if the bitmap width and height are both smaller than imageview's width and height, then you
don't need resizing. just set the imageview's bitmap and center the gravity.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
then I will have more opportunities to fit the map into image view then use webview
1. You have much more opportunities if NOT using a WEBVIEW.
2. The javascript api (i guess you are using this one) is not a free service. Android Maps Api IS: why not use GoogleMaps instead?
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
1. You have much more opportunities if NOT using a WEBVIEW.
2. The javascript api (i guess you are using this one) is not a free service. Android Maps Api IS: why not use GoogleMaps instead?
You are right Manfred. It is more convenient to use a ImageView and fill it with data from theWEB - static map API URL
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…