简体   繁体   English

优先点击多段线而不是标记Google Maps Android

[英]Prioritize click polyline instead of marker google maps Android

I have an app in which lines are drawn and above these I have a marker that shows the information of the line. 我有一个应用程序,其中绘制了线条,而在这些应用程序上方,我有一个显示该行信息的标记。

  • The lines are clickable 线是可点击的
  • I'm using Bitmap, Paint and Canvas to draw the marker. 我正在使用位图,绘画和画布绘制标记。

Code for draw the lines 画线的代码

Polyline polyline = googleMap.addPolyline(line.getPolylineOptions());
polyline.setTag(linea);
polyline.setClickable(clickeable);
polyline.setZIndex(1.0f);

Code for draw markers 绘图标记代码

Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bmp = Bitmap.createBitmap(150, 30, conf);

Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setTextSize(18);

Canvas canvas = new Canvas(bmp);
canvas.drawText(text, 15, 15, paint);

canvas.save();

Marker m = googleMap.addMarker(new MarkerOptions()
        .position(latLng)
        .zIndex(-1.0f)
        .icon(BitmapDescriptorFactory.fromBitmap(bmp))
);

I need that when clicking on the line click on this and not on the marker. 我需要在单击该行时单击它,而不是在标记上。

I have tried with Z-Index but it does not work. 我已经尝试过使用Z-Index,但是它不起作用。

Please help. 请帮忙。

I did not find a way to prioritize the line instead of the marker. 我没有找到一种方法来对行而不是标记进行优先排序。

See https://developers.google.com/maps/documentation/android-api/marker?hl=es-419#click-index 请参阅https://developers.google.com/maps/documentation/android-api/marker?hl=es-419#click-index

Markers are effectively considered to be in a separate z-index group compared to other overlays or shapes (polylines, polygons, circles, and/or ground overlays), regardless of the z-index of the other overlays. 与其他叠加层或形状(折线,多边形,圆形和/或地面叠加层)相比,标记被有效地视为位于单独的z-index组中,而与其他叠加层的z-index无关。 If multiple markers, overlays or shapes are overlaid on top of each other, the click event is cycled through the cluster of markers first, then triggered for other clickable overlays or shapes, based on their z-index values. 如果多个标记,叠加层或形状彼此叠加,则单击事件首先在标记群中循环,然后根据其z索引值触发其他可点击的叠加层或形状。

Instead I call the same method in: 相反,我在以下方法中调用了相同的方法:

onMarkerClick ()

And

OnPolylineClickListener ()

The same functionality is used when clicking on the line or the marker of this. 单击行或标记时,将使用相同的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM