- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我关注 mapsforge 库有一段时间了,我喜欢这个库的工作方式。
在我的项目中,我需要不同类型的标记。一种类型应该在点击时显示一个关于标记的对话框,而另一种类型应该在点击时为标记的坐标干杯。
所以我创建了 Marker 类的两个子类 PoiMarker 和 LocationMarker 并因此为这两个子类覆盖了 onTap() 的方法。现在,当我添加第一个标记 (PoiMarker) 时,一切都很好,并且显示了对话框。然后,当我添加第二个标记 (LocationMarker) 时,也会显示 toast ,但是当我点击第一个标记时,它会显示 toast 而不是对话框。在我点击 map 上的任何位置时,它都会显示 toast 而不是对话框。
我意识到,在向 map View 添加标记时,我们正在向 map View 添加一个图层,而当我添加另一个标记时,新图层只是覆盖前一个标记,而不会遇到第一个标记的点击。
即使在我添加了新的第二个标记后,如何使第一个标记可点击?
谢谢
最佳答案
无需为多个标记类型创建多个类,只需创建一个新类,扩展标记并添加标记类型属性并覆盖 onTap:
public class DescriptedMarker extends Marker {
public DescriptedMarker(LatLong latLong, Bitmap bitmap, int horizontalOffset, int verticalOffset) {
super(latLong, bitmap, horizontalOffset, verticalOffset);
}
public String marker_description;
public int marker_type;
private Runnable action;
public void setOnTabAction(Runnable action){
this.action = action;
}
@Override
public boolean onTap(LatLong tapLatLong, Point layerXY, Point tapXY) {
double centerX = layerXY.x + getHorizontalOffset();
double centerY = layerXY.y + getVerticalOffset();
double radiusX = (getBitmap().getWidth() / 2) *1.1;
double radiusY = (getBitmap().getHeight() / 2) *1.1;
double distX = Math.abs(centerX - tapXY.x);
double distY = Math.abs(centerY - tapXY.y);
if( distX < radiusX && distY < radiusY){
if(action != null){
action.run();
return true;
}
}
return false;
}
}
现在您可以轻松创建多种类型的市场:
org.mapsforge.core.graphics.Bitmap bmp = AndroidGraphicFactory.convertToBitmap(getResources().getDrawable(R.drawable.myMarkerDrawable));
//pos is a LatLong variable
final DescriptedMarker marker = new DescriptedMarker(pos,bmp,0,0);
marker.marker_type = x; //x is an int and determine marker type
marker.setOnTabAction(new Runnable() {
@Override
public void run() {
if(marker.marker_type == 0)
Application.toast_short(marker.marker_description);
else if(marker.marker_type == 1)
{
//display a dialog for example
}// you can add many if for many types
}
});
关于android - Mapsforge on tap listeners 用于多个标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33688193/
我想在运行时向 MapsForge 添加一些 Overlay 项目;我可以成功添加它们,但它们只有在我移动或缩放 map 后才会出现。实际上应该如此,因为在每次移动或缩放时,MapsForge 都会通
我可以让 Mapsforge lib 0.30 在 Android 上运行,我真的很满意。我遇到的问题是我无法以正确的方式添加自定义可绘制对象。当我添加要绘制的 drawable 时,drawable
MapsForge map 是否存在 zoomToSpan 方法?如果不存在,我该如何实现?有没有一些代码示例或算法描述? 提前致谢 最佳答案 您可以使用以下方法扩展 MapView(MapsForg
我目前正在使用 mapsforge ( https://github.com/mapsforge/mapsforge/ ) 开发原生安卓应用程序。我可以使用单个国家/地区的离线 map ,但稍后需要有
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improve
我正在为滑雪者和单板滑雪者开发一款 Android 应用程序,它可以将用户从一个点导航到另一个点。 为了显示 map ,我使用 Mapsforge-Version 0.4.0。 我在 map 上添加了
我正在尝试安装用于渗透的mapsforge-mapwriter-plugin,但我无法让它工作。 我尝试了普通的基于 shell 的版本和页面上提到的方法:“http://code.google.co
我正在尝试创建一个 mapsforge 离线 map 应用程序。我遵循了指南或那里的网站下面是我的代码的快照 但是当我运行这个应用程序时,应用程序崩溃了。 logcat 如下。 但是,如果我在 mai
我关注 mapsforge 库有一段时间了,我喜欢这个库的工作方式。 在我的项目中,我需要不同类型的标记。一种类型应该在点击时显示一个关于标记的对话框,而另一种类型应该在点击时为标记的坐标干杯。
我正在尝试使用 Mapsforge 在我的 Android 应用程序中绘制一条简单的路线。我按照一个示例创建了单点 OverlayItems。但是当我尝试绘制路线时,我在 map 上看不到任何东西。有
我知道这里有一些针对 Mapsforge fragment 的补丁:https://code.google.com/p/mapsforge/issues/detail?id=177 .但是我不确定如何
我对使用库有点陌生,想在这里寻求一些基本帮助。 我一直在尝试在这里使用 Mapsforge 的 .jar 库:https://code.google.com/p/mapsforge/downloads
我读过 mapsforge wiki它有一个示例页面“/trunk/Applications/Android/Samples”。 It现在好像死了 我在哪里可以得到它? 最佳答案 您可以在 here
我一直在尝试运行 mapsforge 项目提供的一些应用程序。我按照此处给出的说明进行操作: ( http://code.google.com/p/mapsforge/wiki/GettingStar
请帮助我进行android编程。我正在制作一个 android mapsforge 应用程序,并希望使用 Mysql 在 Android Mapsforge map 上添加多个标记。我的数据位于数据库
我从 mapsforge 服务器下载了一个 map 文件 (.map),现在我该如何编辑或向该文件添加一些信息? 例如我想更改一些街道名称 最佳答案 如果此文件遵循OSM XML schema那么你可
我的 iPhone 应用程序需要一些框架,它使用 map 。现在这些 map 是光栅图像,我想通过制作矢量 map 来优化我的应用程序。我知道我的 Android 开发同事为此目的使用了 Mapsfo
我使用 MapsForge 0.8在我的 Android 应用中显示 map 。当使用在线图 block (只是位图而不是可以在运行时渲染器中调整的 vector 数据)时, map 在我的高分辨率设
我需要在我的 Android Studio 应用中使用 Mapsforge(离线 map )。我已经导入了这些库: mapsforge-core-0.4.0.jar mapsforge-map-0.4
我正在尝试运行 mapsforge 项目中最简单的 map 查看器示例: A very basic Android app example - GitHub使用 Android Studio。 在应用
我是一名优秀的程序员,十分优秀!