Search code examples
androidwebviewopenlayersopenstreetmap

OpenLayers Android WebView Uncaught TypeErrors


I have a webpage with OpenLayers working in desktop browsers. When I embed it to a WebView, or XWalkView, I start getting Ungaught TypeErrors and the map remains blank; the zoom buttons and credits appear though.

I tried the simple example they provide in the documentation (CASE 1): http://wiki.openstreetmap.org/wiki/OpenLayers_Marker

And I also tried the mobile example with the development version of OpenLayers (CASE 2): http://openlayers.org/dev/examples/mobile.html

CASE 1---------------------------------

With the case one, when the webpage loads i get the following error in Logcat:

07-03 16:31:58.639: I/chromium(12085): [INFO:CONSOLE(185)] "Uncaught TypeError: Cannot read property 'w' of null", source: http://www.openlayers.org/api/OpenLayers.js (185)

The webpage loads and shows the buttons and credits but not the map or markers. Then I move the white map with the fingers and I start getting the following error and similar ones:

 07-03 16:32:34.679: I/chromium(12085): [INFO:CONSOLE(184)] "Uncaught TypeError: Cannot read property 'y' of null", source: http://www.openlayers.org/api/OpenLayers.js (184)

CASE 2---------------------------------

Since the webpage works in desktop browsers, I thought that maybe the library for mobile was different. I found the other example, using a different version of the library (openlayers.mobile.js), but I get exactly the same errors.

This version does not work on desktop, throwing the following error, but I guess is normal: Failed to load resource: net::ERR_FILE_NOT_FOUND file://a.tile.openstreetmap.org/3/4/2.png

I am trying to find a way to embed a map in an Android application to dynamically plot paths on the map. I have another two browsers with WebGL models in this app. The first time, I tried to use the MapView of OpenStreetMaps for Android (osmdroid), it works but not among the other browsers. Every time I loaded one of the browsers and then went to the mapview, after some seconds it crashes without exceptions or warnings. So, I decided to put a third browser and put the map using openlayers, to follow the same structure than before, but now I have this error and I am stuck.

Edit 1:

it works locally with the Android browser apps but not the webviews


Solution

  • These errors appear before the tiles are loaded, when trying to move and zoom the map. They don't mean that the script has crashed because once the tiles are loaded, they disappear and the map works "correctly".