Search code examples
javascripthere-api

Can the HERE JavaScript API be used offline?


I have a very basic question about the HERE JavaScript API. I recently started looking into HERE Maps and even got an Android app working with HERE's android SDK. In an app, I can download map data and use the app offline. After this, though, I would also like to create a project with the HERE JavaScript API for desktop and mobile.

So, my question is can the HERE JavaScript API work offline just like the Android SDK when it comes to both mobile and desktop use? Is it the same process - download data and simply point to it? Or does the HERE JavaScript API require constant online use? I couldn't find a straight answer on the HERE documents so any clarification would be very helpful. Thank you!


Solution

  • No, the HERE JavaScript API can't work offline just like the Android SDK because e.g. HERE SDKs for mobile devices have also Routing, Geocoding, etc. APIs which are capable to work offline, unlike HERE JavaScript API.

    HERE JavaScript API can only store persistently the content of a raster map layer for a given area and range of zoom levels. See H.Map#storeContent for more details.

    It can be used to enable map rendering when no internet connection is available and also to reduce the download traffic for frequently visited map areas. Currently this supports only raster tiles (not vector tiles!). See please example:

      map.storeContent(
       function(req) {
         if (req.getState() === H.util.Request.State.COMPLETE) {
          console.log('Raster tiles of maps base layer stored successfully.');
         }
         else if(req.getState() === H.util.Request.State.ERROR) {
           console.log('Something happened, storing the content was not successful.');
         }
       },
        map.getViewModel().getLookAtData().bounds.getBoundingBox(),
        map.getZoom(), 
        map.getZoom() + 2
      );
    

    The code above stores raster tiles for the current viewport from current zoom to current zoom + 2. After that you can turn off your wifi and zoom the map to see tiles are loaded from browser cache.