Android Question Simple OSM Viewer

Sergey_New

Well-Known Member
Licensed User
Longtime User
Using the example made a small application for B4A.
It works well on the emulator, but, unfortunately, on the device, the "+" and "-" buttons are very small. Clicking on them doesn't work. Gestures works.
What can be changed?
 

Attachments

No one knows?
Has anyone tested the attached example and the result is the same?
 
Upvote 0
Dont clear. There is currently a map with London detection on my Samsung S7.

1.png
 
Last edited:
Upvote 0
Everything is displayed on my emulator and on the device. I do not understand what is going on? :(
 
Upvote 0
Using the example made a small application for B4A.
It works well on the emulator, but, unfortunately, on the device, the "+" and "-" buttons are very small. Clicking on them doesn't work. Gestures works.
What can be change
Shows London map on Samsung Ultra 21. +/- doesn't do anything, but zoom gesture works Have you put SetApplicationAttribute(android:usesCleartextTraffic, "true") in manifest project file?
 
Upvote 0
bparent, thank God, at least it works for you :)
Shows London map on Samsung Ultra 21. +/- doesn't do anything, but zoom gesture works Have
I have the same.
Have you put SetApplicationAttribute(android:usesCleartextTraffic, "true") in manifest project file?
No, I didn't put it in..
Added to the manifest - nothing has changed.
Checked the code in B4J. The scale is changed both by +/- and by the mouse wheel.
Attached the project on B4J.
 

Attachments

Upvote 0
I've never used WebView and I am no good on webby stuff but it seems that in B4A after WebView1.LoadHtml is called it raises the PageFinished event but with a Url of "file:///".

On the other hand the project on B4J works fine but it doesn't seem to raise the PageFinished event at all

I don't understand what's happening here :(
 
Upvote 0
If you target SDK 27 it displays the map, although the +/- buttons don't seem to work. Target SDK 28 or higher and it doesn't work. I assume some permissions or other security was added at 28 but at the moment I haven't identified what it might be. You will need to uninstall the app before loading it to target a lower SDK.

Also nowadays it really should be using https rather than http - just add the 's' and it works anyway.
 
Upvote 0
What can be changed?
You are using Javascript in the HTML but did not added any javascript possibility to your app?`WHY?

I get this message when using webviewextras

Uncaught ReferenceError: OpenLayers is not defined in file:/// (Line: 12)
Are you sure the javascript does work on android in a limited webview? Note that webview is not compareable with a Webbrowser on Android
 
Upvote 0
I'm probably wrong about just adding 's' to make it https working but I got it working targetting SDK 30 by adding ClearText to the manifest.

B4X:
' 28 - Non-ssl (non-https) communication is not permitted by default.
' It can be enabled in B4A v9+ by adding this line to the manifest editor:
CreateResourceFromFile(Macro, Core.NetworkClearText)
 
Upvote 0
?
You need to declare the css style sheet, also it is a very old api, the documentation is not online and you should download it from here.
1656062816679.png


HTML:
    <html>
    <head>
    <meta charset="utf-8" />
    <title>OpenStreetMap</title>
    <link rel="stylesheet" href="https://openlayers.org/api/2.13.1/theme/default/style.css" type="text/css">
    <style>html, body, #map {width: 100%;height: 100%;margin: 0;padding: 0;}</style>
    </head>
    <body>
      <div id="mapdiv"></div>
      <script src="https://openlayers.org/api/2.13.1/OpenLayers.js"></script>
      <script>
        map = new OpenLayers.Map("mapdiv");
        map.addLayer(new OpenLayers.Layer.OSM());
        var lonLat = new OpenLayers.LonLat(${CenterLong}, ${CenterLat})
              .transform(
                new OpenLayers.Projection("EPSG:4326"),
                map.getProjectionObject()
              );
        var markers = new OpenLayers.Layer.Markers( "Markers" );
        map.addLayer(markers);
        markers.addMarker(new OpenLayers.Marker(lonLat));
        map.setCenter (lonLat, ${zoom});
      </script>
    </body></html>
 
Upvote 0
Back
Top