2

I am using Android Map V3 in my application and i already know that there is a bug in Kit-Kat version where the chromium kit throws up this error - nativeOnDraw failed; clearing to background color and doesn't draw the map.

I already had tried the list of solutions given at WebView Rendering Issue in Android KitKat (disable hardware acceleration, change the background color), but none of them worked so far.

Further i also did a few searches in other forums and they have proposed a workaround by setting the borderRadius of the webview to > 0.

My question is how do i set the border radius to the webview? I presume that this is done via a separate js file, but guess i am having some trouble in putting all the pieces together.

Between i see this issue has been there right from the start of Kit-Kat. Haven't they fixed this still?

Note: The view loads a map for a second before going back to the blank state.

My HTML-JS code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>

<head>

    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>

    <style type="text/css">
        html { height: 100% }
        body { height: 100%; margin: 0; padding: 0}
        #map-canvas { height: 100% }
    </style>

    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MY_KEY"></script>

    var map;
    <script type="text/javascript">
      function initialize() 
      {
        var latitude = 0;    
        var longitude = 0;    

        if (window.android)
        {      
            latitude = window.android.getLatitude();      
            longitude = window.android.getLongitude();    
        }    

        var myLatLng = new google.maps.LatLng(latitude,longitude); 

        var mapOptions = {zoom: 20, center: myLatLng, mapTypeId: google.maps.MapTypeId.ROADMAP};

        map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
      }

      google.maps.event.addDomListener(window, 'load', initialize);
    </script>

  </head>

  <body>
    <div id="map-canvas"></div>
  </body>

In my class, i add the above html code (which is saved in the assets folder) to the webview.

map = (WebView) rootView_Parent.findViewById(R.id.mapview);

map.loadUrl("file:///android_asset/mapurl.html");

map.getSettings().setJavaScriptEnabled(true);

map.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Community
  • 1
  • 1
Vikram Ezhil
  • 995
  • 1
  • 9
  • 15
  • Is this an Android Application or a web application? If it's an Android application you should be using, [Maps V2](https://developers.google.com/maps/documentation/android/) and there's no need to use a webview. V3 is for web-based applications. – pointNclick Jan 07 '15 at 21:29
  • @ user1544581 - Its an android application, i did try maps v2 initially but i got an out of memory error when the map runs for a long time. So thought of trying maps V3 in my app to see if it is able to withstand the heavy load. But guess since i didn't get any solution to this question, i resorted back to maps v2 and did a small fix in my code to prevent the out of memory error. – Vikram Ezhil Jan 08 '15 at 14:34
  • Well, I just asked because I was a little confused as to what you're trying to achieve. But given your explanation, that definitely makes some sense. Regarding the WebView issue for L, the workaround that has worked for me (but for videos, haven't tried it on maps) is to not load the content until after the webview is attached and drawing. Maybe you could try the same with your app and see if it works? In case the issue still applies. – pointNclick Jan 08 '15 at 15:55

1 Answers1

0

https://blog.clevertap.com/androids-webview-is-broken/

Sizes that are implemented with percentages may crash your webview, I'm not really certain why, so if you can change that, your webview might work properly.

It took me half a day to find it, but it worked for me.

BTW: I'm doing basically the same as you were (I'm late for this answer, maybe) and it worked like a charm, now.

  • Please don't simply link to external sites as answers. Links are volatile and subject to change in the future. Welcome to Stack Overflow :) – Tyler Jul 22 '16 at 19:59
  • @Tyler, that's why I provided a summary of what actually solved the question - at least for me - below the link. Thanks, btw. – Carlos Moreira Jul 22 '16 at 20:02