AnsweredAssumed Answered

Trouble caching maps in a Service

Question asked by JeffJonesInMT on Oct 6, 2014

Hi all,

 

So far the API has been great, but I'm having trouble trying to complete a feature in my app.

 

I create a service that runs an ExportTilesCacheTask on a time interval, the idea being that the app would automatically cache maps in the background so that the user still has a map available if they lose a data connection.

 

I have already accomplished caching in the maps fragment itself, however transferring this code into a service has caused problems.

 

I believe the culprit is either the Envelope or the SpatialReference that I am passing into the ExportTileCacheParameters instance.

 

Here is my code:

 

 final ExportTileCacheTask tileTask = new ExportTileCacheTask(serviceURL, cred);
  Envelope extentToStore = new Envelope();
  Location lastKnown;
  MainActivity.LocationServicesConnection locService = null;

  lastKnown = waitForLocation(locService);

  extentToStore.centerAt(new Point(lastKnown.getLatitude(), lastKnown.getLongitude()), 0.2, 0.2);
  ArcGISTiledMapServiceLayer layer = new ArcGISTiledMapServiceLayer(serviceURL, cred);

  ExportTileCacheParameters params = new ExportTileCacheParameters(false, 15, 19, extentToStore,  layer.getSpatialReference());

  createTileCache(params, tileTask, Environment.getExternalStorageDirectory().getPath() + DEFAULT_MAP_PATH);

 

I'm not sure if I'm correctly creating the Envelope or the SpatialReference. Pulling the SR from a layer seems hacky and inefficient.

 

In the logcat I first see a "FileNotFoundException" followed by errors in the callbacks from estimateTileCacheSize and generateTileCache.

 

This code works perfectly in my map fragment, so I have to think it's the Envelope or SR causing this. Anyone?

Outcomes