- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在你发表评论后,JaakL 我做了一些工作,这是我所能得到的。不幸的是,它还没有工作。我按照你告诉我的一步一步地做了,但每次我加载应用程序时,我只会看到一个白色的屏幕,而不是我试图加载的漂亮 map 。
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView mapView;
mapView=(MapView)findViewById(R.id.mapView);
// Optional, but very useful: restore map state during device rotation,
// it is saved in onRetainNonConfigurationInstance() below
Components retainObject = (Components) getLastNonConfigurationInstance();
if (retainObject != null) {
// just restore configuration and update listener, skip other initializations
mapView.setComponents(retainObject);
return;
} else {
// 2. create and set MapView components - mandatory
mapView.setComponents(new Components());
}
copyAssets();
try {
MBTilesRasterDataSource dataSource = new MBTilesRasterDataSource(
new EPSG3857(), 0, 19,
(null).getAbsolutePath() + "/braga.mbtiles",
false, this);
RasterLayer mbLayer = new RasterLayer(dataSource, 0);
mapView.getLayers().addLayer(mbLayer);
} catch (IOException e) {
Log.error(e.getMessage());
}
我的调试器的前三行:
27337-27337/com.exaple.myapplication5.app E/Trace﹕ error opening trace file: No such file or directory (2)
27337-27337/com.exaple.myapplication5.app W/ActivityThread﹕ Application com.exaple.myapplication5.app is waiting for the debugger on port 8100...
27337-27337/com.exaple.myapplication5.app I/System.out﹕ Sending WAIT chunk
最佳答案
技巧是您需要将文件从应用程序包复制到设备存储,否则您无法打开 MBtiles 文件。
示例代码:
@Override
public void onCreate(Bundle savedInstanceState) {
// create mapview, settings...
copyAssets();
try {
MBTilesRasterDataSource dataSource = new MBTilesRasterDataSource(
new EPSG3857(), 0, 19,
getExternalFilesDir(null).getAbsolutePath()+"/map.mbtiles",
false, this);
RasterLayer mbLayer = new RasterLayer(dataSource, 0);
// use setBaseLayer() if this is main layer, addLayer() if it is overlay layer
mapView.getLayers().setBaseLayer(mbLayer);
// recenter map to coverage
HashMap<String, String> dbMetaData = dataSource.getDatabase().getMetadata();
String center = dbMetaData.get("center");
String bounds = dbMetaData.get("bounds");
if(center != null){
// format: long,lat,zoom
String[] centerParams = center.split(",");
mapView.setFocusPoint(mapView.getLayers().getBaseLayer().getProjection().fromWgs84(Double.parseDouble(centerParams[0]), Double.parseDouble(centerParams[1])));
mapView.setZoom(Float.parseFloat(centerParams[2]));
Log.debug ("center to point "+Arrays.toString(centerParams));
}else if(bounds != null){
// format: longMin,latMin,longMax,latMax
String[] boundsParams = bounds.split(",");
MapPos bottomLeft = mapView.getLayers().getBaseProjection().fromWgs84(Double.parseDouble(boundsParams[0]), Double.parseDouble(boundsParams[1]));
MapPos topRight = mapView.getLayers().getBaseProjection().fromWgs84(Double.parseDouble(boundsParams[2]), Double.parseDouble(boundsParams[3]));
Log.debug ("center to bounds "+bottomLeft.x+","+topRight.y+","+topRight.x+","+bottomLeft.y);
mapView.setBoundingBox(new Bounds(bottomLeft.x,topRight.y,topRight.x,bottomLeft.y), false);
// check that zoom is within given range
int[] zoomRange = dataSource.getDatabase().getZoomRange();
if(mapView.getZoom() < zoomRange[0]){
mapView.setZoom(zoomRange[0]+1);
}
if(mapView.getZoom() > zoomRange[1]){
mapView.setZoom(zoomRange[1]-1);
}
}else{
// bulgaria
mapView.setFocusPoint(mapView.getLayers().getBaseLayer().getProjection().fromWgs84(26.483230800000037, 42.550218000000044));
// zoom - 0 = world, like on most web maps
mapView.setZoom(5.0f);
Log.debug("center to default");
}
} catch (IOException e) {
Log.error(e.getMessage());
}
// ...
}
private void copyAssets() {
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
} catch (IOException e) {
Log.error("Failed to get asset file list." + e.getLocalizedMessage());
}
for(String filename : files) {
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(filename);
File outFile = new File(getExternalFilesDir(null), filename);
if(!outFile.exists()){
out = new FileOutputStream(outFile);
copyFile(in, out);
out.flush();
out.close();
out = null;
}
in.close();
in = null;
} catch(IOException e) {
Log.error("Failed to copy asset file: " + filename + "\n" + e.getLocalizedMessage());
}
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[32 * 1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
关于android - 使用 Nutiteq 为 Android 导入 .mbfiles 扩展文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23861670/
我是这种开发的新手。我正在尝试创建一个涉及 GPS 跟踪的 android 应用程序。我正在使用 Nutiteq,因为我必须使用 openstreetmap 作为默认 map 。请帮助我。 最佳答案
我已经为 Nutiteq 中的 Polygons 和 Markers 实现了我自己的自定义 MapListener 并且我可以显示 Toasts 并更改元素的颜色和其他内容,但如果我在标记或多边形上长
如何在 Nutiteq 中启用指南针模式? 有方法还是我需要自己创建定向系统? 最佳答案 我现在向 https://github.com/nutiteq/hellomap3d/ 添加了一个 Compa
我正在尝试使用包含三个 Button 的自定义 View 创建 nutiteq ViewLabel。我的代码和问题与这篇文章非常相似nutiteq: Button resp. clickable Vi
与许多其他 map API 类似,nutiteq map API 包含 MarkerLayer可以添加到 map 中。它有一个简单的方法 removing markers (例如:markerLaye
我正在尝试将标记从一个位置动画化到另一个位置。为此,我使用了 nutiteq 示例代码中的以下代码。 MapPos markerLocation0 = baseProjection.fromWgs84
我一直在研究 nutiteq map ,但随着位置的变化,我无法绘制折线。 到目前为止我试过: @Override public void onLocationChanged(Location loc
请提供一些想法,我在跟踪时使用 nutiteq map 绘制折线,但想在跟踪时同时在折线上显示标记。您的善意建议将不胜感激。谢谢 最佳答案 您应该使用带线的几何图层作为折线,并使用带标记的标记层。您可
我要为 Android 平台开发一款基于位置的游戏。我想在随机坐标(用户位置周围)但在路上创建一个标记!此外,我将从这一点 (A) 到第二个随机点 (B) 为该标记制作动画。有什么想法吗? 谢谢! p
我目前正在尝试将离线 map 导入 nutiteq。我从 OpenStreetMap 下载了一张 map ,但该 map 的扩展名为 .osm。我怎样才能将这种扩展导入到 Android? 最佳答案
最近我只是关注了 Nutiteq SDK from here. 的例子 但不幸的是,未找到 MBTilesRasterDataSource。 Eclipse 在该行的变量语句上显示错误。我检查了包 c
我在从 MapQuestApi 的 nutiteq map 上创建路线方向时遇到了一些问题,我知道如何接收所需的信息 @Override public void onSuccess(R
大家好,我已经在我的应用程序中替换了我的 GoggleMaps,因为它没有关闭 map ,因此需要按需清理堆,现在我改用 nutiteq,我正在尝试访问谷歌地图的图 block 。正如 nutiteq
我正在尝试使用以下代码在 map 上绘制一条曲线边缘的线 LineStyleBuilder lineStyleBuilder = new LineStyleBuilder();
您好,我正在开发一个基于 map 的应用程序,我在其中使用 Nutiteq 3D 库来实现 3D View 。但是现在无法在该 3D map 上绘制两点之间的路线。谁能帮我在 Nutiteq 3D 库
如果之前有人问过这个问题,我很抱歉。但是我在处理离线 3d map 时遇到了麻烦。我已经从 github 下载了源代码: https://github.com/nutiteq/hellomap3d 它
我正在寻找使用 nutiteq SDK 从 mapbox 加载 mbtiles 的方法。我知道如何使用这段代码离线加载 mbtiles // 1. Create tile data source fr
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度理解。包括尝试过的解决方案、为什么它们不起作用,以及预
在你发表评论后,JaakL 我做了一些工作,这是我所能得到的。不幸的是,它还没有工作。我按照你告诉我的一步一步地做了,但每次我加载应用程序时,我只会看到一个白色的屏幕,而不是我试图加载的漂亮 map
我能够在 Android nutiteq 中制作完全自定义的 ViewLabel,定义布局设计和尺寸。但是,可点击的 View 未按预期工作。首先,我尝试通过将根布局定义为可点击来使整个标签可点击,但
我是一名优秀的程序员,十分优秀!