3

在我的应用程序中,我想显示带有指针的地图,在指针上方我想显示带有按钮的文本视图。使用该按钮我想移动到下一个活动。以下是我显示该点的代码,但如何显示一个带有文本和右侧按钮的点。以及如何为它编写 btn 动作

class MapOverlay extends com.google.android.maps.Overlay
 {
    public boolean draw(Canvas canvas, MapView mapView,boolean shadow, long when)
    {
        super.draw(canvas, mapView, shadow);                  

        //---translate the GeoPoint to screen pixels---
        Point screenPts = new Point();

        mapView.getProjection().toPixels(p, screenPts);
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);           
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y-100, null);        

        mapView.getProjection().toPixels(q, screenPts);
        @SuppressWarnings("unused")
        Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.blue);           
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y-100, null);        
        return true;
    }
 }



p = new GeoPoint((int) (latPt * 1E6),(int) (lngPt * 1E6));
    Log.e("point p ",""+p);

    mapController.animateTo(p);
    mapController.setZoom(16);
    mapView.invalidate();
    mapView.setTraffic(true);
    mapController = mapView.getController();

    MapOverlay mapOverlay = new MapOverlay();
    List<Overlay> listOfOverlays = mapView.getOverlays();
    listOfOverlays.clear();
    listOfOverlays.add(mapOverlay);
4

1 回答 1

1

我通过使用视图而不是覆盖来做到这一点,因此您使用 addItem 为地图中的每个项目添加一个新视图。这是代码:

注释视图

public AnnotationView(final Context context,final Object object) {
    super(context);
    setOrientation(VERTICAL);
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.map_overlay, this, true);

    // Set the textview

    lBubble = (LinearLayout) findViewById(R.id.lAnnotation);
    txtPlace = ((TextView) (findViewById(R.id.txtPlace)));
    txtPlace.setText(object.getName());

    // set button touch listener

    ((ImageButton) (findViewById(R.id.btnPlace)))
            .setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    //Do anything
                };
            });
    // add your overlay on mapview by geopoint

    btnMarker = ((ImageButton) (findViewById(R.id.btnMarker)));
    btnMarker.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
//Do anything           };
    });

    setLayoutParams(new MapView.LayoutParams(
            MapView.LayoutParams.WRAP_CONTENT,
            MapView.LayoutParams.WRAP_CONTENT, new GeoPoint(
                    (int) (object.getLatitude() * 1E6),
                    (int) (object.getLongitude() * 1E6)),
            MapView.LayoutParams.BOTTOM_CENTER));
}

然后我刚刚创建它并添加到地图中,例如:

overlay = new AnnotationView(this, object);
mapView.addView(overlay);

map_overlay 布局只是您想要在地图上显示为覆盖(图像、按钮...)的线性布局

我只有缩放比例的问题,因为缩放时点会发生一些变化,我试图解决它。

希望有帮助

干杯

于 2013-03-11T09:57:45.830 回答