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 を使用してマップ内の各アイテムに新しいビューを追加します。ここにコードがあります:

AnnotationView

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 レイアウトは、マップ上にオーバーレイ (画像、ボタンなど) として表示する linealayout です。

ズーム中にポイントが少し変化するため、ズームスケールに問題があるだけです。解決しようとしています。

それが役立つことを願っています

乾杯

于 2013-03-11T09:57:45.830 に答える