【问题标题】:Android map with a textview over the point and with a buttonAndroid 地图在点上有一个文本视图并带有一个按钮
【发布时间】:2011-12-25 00:51:49
【问题描述】:

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

【问题讨论】:

    标签: android button map marker


    【解决方案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 布局只是您希望在地图上显示为叠加层(图像、按钮...)的线性布局

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

    希望有帮助

    干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-19
      • 2013-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多