ThinkGeo.com    |     Documentation    |     Premium Support

Use google maps offline

Hello, I would like to know how I can export the background map of google maps to use offline in my android application?

Hi Elton,

Please use FileBitmapTileCache, it can saved the tile you viewed and you can view it offline again.

Regards,

Don

I did one function which export the map, but when I call occurs one error:

System.Net.WebException: The remote server returned an error: (403) Forbidden.

Bellow is the code what I using. The error occur in the command mapEngine.DrawStaticLayers(bitmap, mapUnit);

for (int i = 0; i < zoomLevels.Count; i++)
{
MapSuiteTileMatrix tileMatrix = new MapSuiteTileMatrix(zoomLevels[i].Scale, tileWidth, tileHeight, mapUnit);
BitmapTileCache tileCache = new FileBitmapTileCache(“C:/MapaOffline”, “google_ruas”, TileImageFormat.Png, tileMatrix);
RowColumnRange rowColumnRange = tileCache.TileMatrix.GetIntersectingRowColumnRange(cacheExtent);

                for (long row = rowColumnRange.MinRowIndex; row <= rowColumnRange.MaxRowIndex; row++)
                {
                    for (long column = rowColumnRange.MinColumnIndex; column <= rowColumnRange.MaxColumnIndex; column++)
                    {
                        // Get tile extent for every tile image
                        RectangleShape tileExtent = tileCache.TileMatrix.GetCell(row, column).BoundingBox;

                        using (Bitmap bitmap = new Bitmap(tileWidth, tileHeight))
                        {
                            mapEngine.CurrentExtent = tileExtent;
                            mapEngine.OpenAllLayers();
                            
                            try
                            {
                                mapEngine.DrawStaticLayers(bitmap, mapUnit);
                            }
                            catch (Exception ex)
                            {
                                throw ex;                                    
                            }
                            
                            mapEngine.CloseAllLayers();

                            BitmapTile tile = new BitmapTile(bitmap, tileExtent, zoomLevels[i].Scale);
                            tileCache.SaveTile(tile);
                        }
                    }
                }
            }

Hi Elton,

You misunderstand my reply, I means you can assign FileBitmapTileCache to your layer, then when you view the map, the viewed tile image will be cached local and you can view them again when offline.

If you want to pre-build image tiles, you should want to view our sample from wiki or product center, it’s name is “Tile Cache Generator”.

From your exception “The remote server returned an error: (403) Forbidden”, that should because you don’t have license to view the Google’s map tiles, please make sure you have license for that.

And we don’t suggest cache the image tile from Google, please view their documentation to make sure it’s legal.

Regards,

Don