Prevent Google maps cache in android webview

Question

I am loading google maps in my WebView using a local html file (assets folder). The map has a kml overlay. The problem I'm facing is that when the kml file is updated, the respective changes are not being reflected in my WebView. I also tried removing the files, in which case, the map still shows the previously loaded overlays. So I assume its related to cache. For preventing caching, I tried using manifest in html, but it was not successful. My codes are as follows.

    wv_map.getSettings().setJavaScriptEnabled(true);

    wv_map.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

    wv_map.clearCache(true);

    wv_map.clearHistory();

    wv_map.loadUrl("file:///android_asset/content.html");

The content.html being:

<!DOCTYPE html>

<html manifest="map.cache">

<head>

    <meta charset="utf-8">

    <title>KML Layers</title>

    <style>

        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }

        #map {
            height: 100%;
        }


        #map img {
            opacity: .4;
        }


        .gmnoprint a, .gmnoprint span {
            display:none;   //remove copyright and terms of use
        }

        .gmnoprint div {
            background:none !important;
        }

        .gm-style-mtc {
            display: none;  //remove satellite option
        }

    </style>

</head>


<body>

    <div id="map"></div>

    <script type="text/javascript">


            function initMap() {

                layer0 = new google.maps.KmlLayer(*MY_URL_TO_KML_FILE*,
                {
                    preserveViewport: true
                });


                var map = new google.maps.Map(document.getElementById('map'),{
                  zoom: 2,
                  center: {lat: 10, lng: 120},

                  streetViewControl: false  //remove the icon of person from the map
                });


                layer0.setMap(map);

            }

    </script>


    <script async defer
            src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&callback=initMap">
    </script>

</body>

map.cache (in same location as content.html) file's content is:

CACHE MANIFEST
#CACHE
#cache nothing
NETWORK:
*

Finally, the kml file is:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">

  <Document>

    <GroundOverlay>

        <color>#7cff0000</color>

        <drawOrder>1</drawOrder>

        <Icon>
            <href>URL_TO_OVERLAY_IMAGE</href>
        </Icon>

        <LatLonBox>
          <west>90</west>
          <east>95</east>
          <south>-19</south>
          <north>25</north>
        </LatLonBox>

    </GroundOverlay>

 </Document>

</kml>

I update the overlay image via Icon tag.

Thanks.


Show source
| caching   | webview   | android   | google-maps   | kml   2016-12-18 05:12 0 Answers

Answers to Prevent Google maps cache in android webview ( 0 )

Leave a reply to - Prevent Google maps cache in android webview

◀ Go back