我正在使用以下代码创建标记(位图),如何为标记添加click事件。我使用graphhopper android for OSM map
startMarker = createMarker(startPoint, R.drawable.marker_departure); layers.add(startMarker);
添加使用createMarker方法
public Marker createMarker(LatLong p, int resource) {
Drawable drawable = activity.getResources().getDrawable(resource);
Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
return new Marker(p, bitmap, 0, -bitmap.getHeight() / 2);
}
以及如何在标记
附近添加文字提前致谢
答案 0 :(得分:2)
我使用以下代码为我工作
MyMarker frommarker = newMyMarker(activity,newLatLong(fl.latitude,fl.longitude), AndroidGraphicFactory.convertToBitmap(activity.getResources().getDrawable(R.drawable.marker_departure)), 0, 0);
mapView.getLayerManager().getLayers().add(frommarker);
和mymarker类
public class MyMarker extends Marker {
private Context ctx;
public MyMarker(Context ctx, LatLong latLong, Bitmap bitmap, int horizontalOffset,
int verticalOffset) {
super(latLong, bitmap, horizontalOffset, verticalOffset);
this.ctx = ctx;
}
@Override
public boolean onTap(LatLong tapLatLong, Point layerXY, Point tapXY) {
if (this.contains(layerXY, tapXY)) {
}
}

答案 1 :(得分:0)
试试这个,可能会有所帮助。
layers.setOnMarkerClickListener(new OnMarkerClickListener()
{
@Override
public boolean onMarkerClick(Marker arg0) {
//Your stuff
});