如何保存谷歌地图在android系统?以及如何使用tileprovider [英] How to save google map in android ?and How to use tileprovider
问题描述
我使用互联网创建一个Android的谷歌地图,但我不知道如何保存谷歌地图在一个Android应用程序。结果
例如:Android地图应用。
I am creating an Android Google map using internet, but I don't know how to save Google map in an Android app.
Example: Android Maps App.
请帮我
推荐答案
从不同的来源你可以蛴螬瓷砖。这是实现TileProvider的您可以与GoogleMap的使用哪个抢GoogleMapTiles
You can grub tiles from different sources. This is implementation of TileProvider which you can use with googleMap which grab GoogleMapTiles
public class GoogleMapOfflineTileProvider implements TileProvider
{
private static final String UPPER_ZOOM_TILE_URL;
static
{
UPPER_ZOOM_TILE_URL = "http://mt0.google.com/vt/lyrs=m&hl=ru&x=%d&y=%d&z=%d&scale=1&s=Galileo";
}
private static final String TAG = GoogleMapOfflineTileProvider.class.getName();
private SQLiteMapDatabase sqLiteMapDatabase;
public GoogleMapOfflineTileProvider(File file)
{
this(file.getAbsolutePath());
}
public GoogleMapOfflineTileProvider(String pathToFile)
{
sqLiteMapDatabase = new SQLiteMapDatabase();
sqLiteMapDatabase.setFile(new File(pathToFile));
}
@Override
public Tile getTile(int x, int y, int z)
{
Tile tile = NO_TILE;
if ( sqLiteMapDatabase.existsTile(x, y, z) )
{
tile = new Tile(256, 256, sqLiteMapDatabase.getTile(x, y, z));
}
else if ( z < 11 )
{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
getBitmapFromURL(x, y, z).compress(Bitmap.CompressFormat.JPEG, 100, stream);
tile = new Tile(256, 256, stream.toByteArray());
}
return tile;
}
public static Bitmap getBitmapFromURL(int x, int y, int z)
{
Log.d(TAG, String.format(UPPER_ZOOM_TILE_URL, x, y, z));
try
{
URL url = new URL(String.format(UPPER_ZOOM_TILE_URL, x, y, z));
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setDoInput(true);
connection.connect();
return BitmapFactory.decodeStream(connection.getInputStream());
}
catch (IOException e)
{
Log.d(TAG, "exception when retrieving bitmap from internet" + e.toString());
return null;
}
}
}
这样你就可以缓存切片到你的数据库中的x / y和缩放。或者你也可以保存特定区域。而就后重新使用它们。将其设置为谷歌地图使用:
so you can cache tiles into your database by x/y and zoom. Or you can save specific area. And after just reuse them. To set it for google maps use:
tileProvider = new GoogleMapOfflineTileProvider(file);
offlineOverlay = googleMap.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider).zIndex(3000));
重要提示:您可以根据谷歌的许可协议的移动设备只能暂时用这个类型的缓存
IMPORTANT : you can use this kind of caching only temporarily on mobile devices according google license agreement.
这篇关于如何保存谷歌地图在android系统?以及如何使用tileprovider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!