我已将可绘制形状的自定义地图标记添加到我的 Google 地图中。这些标记是各种颜色的点。当用户点击其中一个标记时,一条折线会从源位置绘制到所选标记;见图1;
图 1:我当前的地图
该线直接绘制到由彩色点标记的坐标。然而,正如紫色点清楚地表明,标记被绘制在顶部 - 我宁愿折线与圆的中心相交,这样每个角度的线看起来更像这样;
/] http://milspace.viecorefsd.com/~nlehman/example.png
图 2:所需的折线圆交点
为了实现这一点,我尝试通过点半径来平移支持可绘制对象的画布。这是我的尝试;
// Circular marker.
final int px = getResources().getDimensionPixelSize(dimen.map_dot_marker_size);
final Bitmap mDotMarkerBitmap = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(mDotMarkerBitmap);
final Drawable shape = getResources().getDrawable(drawable.purple_map_dot);
shape.setBounds(0, 0, px, px);
canvas.translate(0, px/2);
shape.draw(canvas);
final MarkerOptions options = new MarkerOptions();
options.position(spot.getNearestCityLatLng());
options.icon(BitmapDescriptorFactory.fromBitmap(mDotMarkerBitmap));
options.title(spot.getNearestCity());
lastLocationSelectionMarker.addMarker(options);
这段代码确实移动了可绘制对象,但支持画布的大小保持不变,这意味着圆圈被切成两半,另一半不可见。
社区能否建议如何最好地实现我在图 2中所追求的效果,标记中心直接位于它标记的坐标上方?