NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Good evening everyone,

I am currently trying to display the OSM from Openlayer3 using javascript in an HTML page. As long as I stay on a classic webpage (on local with a tomcat) it work just fine and I display my own datas from a GeoJson file.

Now i want to do the same on an android webview using the same HTML & JS files, exported openlayers.js/css and the html in the assets folder. The problem is the map itself doesn't show, just the controls and copyright at the bottom. I have allowed javascript in my webview as i can execute other function from a JavascriptInterface class.

Is there any restrictions with openlayers/osm and android ?

Note : I am currently restricted to just Openlayers and a webview for this project, so i can't use things like leaflet or any Google API.

My current code is :

public class MapActivity extends AppCompatActivity {

private HashSet<Point> points;
private WebView webView;
private WebSettings wSettings;
private AssetManager assetManager;

protected void onCreate(Bundle savedInstanceState) {
    assetManager = getApplicationContext().getAssets();
    try {
        InputStream targetStream ="lieuxjson.json");
        points = GeoJsonParser.readJsonStream(targetStream);
    } catch ( e) {
        //stop activity
    WebView webView = new WebView(this);
    wSettings = webView.getSettings();
    WebClientClass webViewClient = new WebClientClass();
    WebChromeClient webChromeClient = new WebChromeClient();
    webView.addJavascriptInterface(new WebAppInterface(this), "Android");

And the JS with a div id="map" and ol.js & ol.css imported :

var world = new ol.layer.Tile({ source: new ol.source.OSM() });

var myview = new ol.View({
    center: ol.proj.fromLonLat([37.41, 8.82]),
    zoom: 3

var map = new ol.Map({
  target: 'map',
  layers: [world],
  view: myview

asked 22 Dec '17, 14:08

Bruce%20Swain's gravatar image

Bruce Swain
accept rate: 0%

edited 22 Dec '17, 16:53

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 22 Dec '17, 14:08

question was seen: 3,947 times

last updated: 22 Dec '17, 16:53

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum