ThinkGeo.com    |     Documentation    |     Premium Support

Showing google map when offline

Hi,

We are currently using google map layer in single tile configuration for Android and iOS using Xamarin forms. Is there a way to downloaded and store google maps tiles locally on device so that we can show it in map when user is offline.

Hi @Thenishreddy,

Caching is not possible in single tile mode. If you want to cache any layer, it needs to be in multi-tile mode.

Thanks,
John

Hi John,

Is there a way to manually download cache in multi-tile mode. what we are seeing on map on press of button and saving that data and again reloading it when in offline ?

Hi @Thenishreddy,

Any layer in multi-tile mode with the cache enabled will write tiles to the cache folder automatically. If you’re looking to highlight an area and then automatically download that area for all zoomlevels at once without the user having to visit every tile at every zoomlevel, then you can check out our TileCacheGenerator video and sample.

This sample uses an older version of ThinkGeo. But the concept still applies. You can use this sample as a template to write your own code to pre-cache an area.

Thanks,
John

Hi John,

Thanks for providing the sample. I was able to implement cache download functionality that downloads current extent in 4 zoom levels from current zoom level and I can see the cached data. But when I am trying application offline I am not able to see cached data. Some difference I found was internal thinkgeo cached folders had different names than folders that I created using my download logic. thinkgeo is creating folders with 1889,1890,1891 while my logic is creating folders with names 202209,202210,202211

Can you help me figure out what’s getting wrong here. attaching sample for your reference.

GoogleCache.zip (836.6 KB)

Hi @Thenishreddy,

When you ran the cache sample to cache the tiles, was it using v10 or v13. Our folder cache strategy changed some between 10 and 13. If you’re using the cache with v13, then the cache will need to be generated with v13 as well.

Thanks,
John

Hi John,

Right now code runs in our android application that downloads the cache and we are using think geo version 13.1.0.

1.How can we generate cache with V13 is there flag for it or we need any code changes?

2.Currently cache think geo generate is 340 x 340 I think its dynamic based on screen size while We are generating 256 x 256 how can we get tile height and width dynamically based on device.

Hi @Thenishreddy,

Your suspicions are correct. On mobile, the size of the tile is determined by the scale factor that the device is running in. For the tiles to be 340x340, it must be ~1.32 scale factor. To see the scale factor for your device, you can use the following code:
var scaleFactor = context.Resources.DisplayMetrics

If you want to cache your own layers, you will need to rebuild the TileCacheGenerator using ThinkGeo Mobile and your pre-caching will have to be on an emulator with the same scale factor.

Finally, comes the question of legality. We removed the TileCache property from our GoogleMapsOverlay because google does not allow caching. But I assume your’e using a GoogleMapsLayer inside of a regular LayerOverlay and are trying to cache that? This is not in accordance with Google’s license, so we do not recommend it even though it is possible. But you will notice a google watermark on each tile when you choose to do this because of the way the google maps api is structured.

If you really want to have an offline cache that is legal, performant and simpler to implement, we recommend you check out ThinkGeo Cloud.

Let me know if I misunderstood your comment above or if you have additional questions.

Thanks,
John