是否有办法在MapView(纬度/经度区域)中占据特定区域而不是像素区域的形状(可绘制或任何形状的形状)。我需要用于GeoPoint群集目的
如果无法做到这一点,我们将非常感谢任何有关投影坐标的指导。但是使用MapView画布执行此操作似乎并不符合性能,因为我一直在回收我的叠加项目,我希望我也可以利用它。
答案 0 :(得分:1)
我正在从我的代码中剔除,所以这可能不会开箱即用,但是应该给你足够的信息来解决这个问题......
扩展课程:
public class MyOverlay extends ItemizedOverlay<OverlayItem>
{
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
private OverlayItem item;
public MyOverlay(Drawable defaultMarker, Context context)
{
super(boundCenterBottom(defaultMarker));
mContext = context;
}
public void addOverlay(OverlayItem overlay)
{
mOverlays.add(overlay);
}
public void doPopulate()
{
populate();
}
@Override
protected OverlayItem createItem(int i)
{
return mOverlays.get(i);
}
@Override
public int size()
{
return mOverlays.size();
}
}
然后在你的活动中......
public void addLocations(GeoPoint _center)
{
final GeoPoint center = _center;
mapOverlays = mapView.getOverlays();
Drawable drawable = MyActivity.this.getResources().getDrawable(R.drawable.map_annotation_pin);
itemizedoverlay = new ScoopOverlay(drawable,mContext);
//add as many points as you wish...
itemizedoverlay.addOverlay(
new OverlayItem(new GeoPoint(/*lon lat data here*/));
);
showResults.sendEmptyMessage(0);
}
private Handler showResults = new Handler()
{
@Override
public void handleMessage(Message msg)
{
itemizedoverlay.doPopulate();
mapOverlays.add(itemizedoverlay);
mapView.invalidate();
}
};
答案 1 :(得分:0)
因此解决方案是绘制到包含项目的ItemizedOverlay。
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
// cycle through all overlays
for (int index = 0; index < mOverlays.size(); index++) {
OverlayItemExtended item = mOverlays.get(index);
// Converts lat/lng-Point to coordinates on the screen
GeoPoint point = item.getPoint();
Point ptScreenCoord = new Point();
mapView.getProjection().toPixels(point, ptScreenCoord);
Paint boxPaint = new Paint();
boxPaint.setColor(android.graphics.Color.WHITE);
boxPaint.setStyle(Paint.Style.FILL);
boxPaint.setAlpha(140);
canvas.drawCircle(ptScreenCoord.X, ptScreenCoord.y,
20, boxPaint);
}
}