2011-11-09 80 views
3

在我的應用我想顯示地圖指針,我想指針上方顯示一個按鈕文本視圖。使用該按鈕我想要移動到下一個活動。以下是我的代碼來展示這一點,但是如何在文本和按鈕右側顯示一個點。而如何寫BTN行動吧Android的地圖與一個TextView在點一個按鈕

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); 

回答

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的地圖作爲覆蓋(圖像,按鈕...)

我只有一個縮放比例的問題,因爲點在縮放時有點改變我正試圖解決它。

希望幫助

乾杯

相關問題