2012-05-06 3 views
2

입니다 :ONTAP이 내 mapActivity

public class MapsActivity extends MapActivity 
{  
    MapView mapView; 
    MapController mc; 
    GeoPoint p; 
    GeoPoint geopoint; 
    GeoPoint geopoint_2; 
    /** Called when the activity is first created. */ 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.map_w); 


     mapView = (MapView) findViewById(R.id.mapView); 
     LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom); 
     @SuppressWarnings("deprecation") 
     View zoomView = mapView.getZoomControls(); 
     zoomLayout.addView(zoomView, 
      new LinearLayout.LayoutParams(
       LayoutParams.WRAP_CONTENT, 
       LayoutParams.WRAP_CONTENT)); 
     mapView.displayZoomControls(true); 
     mapView.setSatellite(true); 
     mc = mapView.getController(); 
     String coordinates[] = {"38.037132", "24.494019"}; 
     double lat = Double.parseDouble(coordinates[0]); 
     double lng = Double.parseDouble(coordinates[1]); 

     p = new GeoPoint(
      (int) (lat * 1E6), 
      (int) (lng * 1E6)); 

     mc.animateTo(p); 
     mc.setZoom(9); 


     geopoint_2 = new GeoPoint((int) (39.204449 *1E6), (int) (24.307251* 1E6)); 
     mapView.getOverlays().add(new DrawableMapOverlay(this,p,R.drawable.pushpin, "test")); 
     mapView.getOverlays().add(new DrawableMapOverlay(this,geopoint_2,R.drawable.pushpin, "test_2")); 
     mapView.invalidate(); 



    } 

    @Override 
    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    } 

이것은

마커를 도청 할 때 내가 원하는
public class DrawableMapOverlay extends Overlay { 

    private static final double MAX_TAP_DISTANCE_KM = 3; 
    // Rough approximation - one degree = 50 nautical miles 
    private static final double MAX_TAP_DISTANCE_DEGREES = MAX_TAP_DISTANCE_KM * 0.5399568 * 50; 
    private final GeoPoint geoPoint; 
    private final Context context; 
    private final int drawable; 
    private final String workerName; 
    /** 
    * @param context the context in which to display the overlay 
    * @param geoPoint the geographical point where the overlay is located 
    * @param drawable the ID of the desired drawable 
    */ 
    public DrawableMapOverlay(Context context, GeoPoint geoPoint, int drawable,String workerName) { 
    this.context = context; 
    this.geoPoint = geoPoint; 
    this.drawable = drawable; 
    this.workerName = workerName; 
    } 

    @Override 
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { 
    super.draw(canvas, mapView, shadow); 

    // Convert geo coordinates to screen pixels 
    Point screenPoint = new Point(); 
    mapView.getProjection().toPixels(geoPoint, screenPoint); 
    Paint paint = new Paint(); 
    // Read the image 
    Bitmap markerImage = BitmapFactory.decodeResource(context.getResources(), drawable); 
    paint.setStrokeWidth(1); 
    paint.setARGB(150, 000, 000, 000); 
    paint.setStyle(Paint.Style.STROKE); 
    // Draw it, centered around the given coordinates 
    canvas.drawBitmap(markerImage, 
     screenPoint.x - markerImage.getWidth()/2, 
     screenPoint.y - markerImage.getHeight()/2, null); 
    canvas.drawText(workerName, screenPoint.x- markerImage.getWidth()/2, screenPoint.y - markerImage.getHeight()/2 , paint); 
    return true; 
    } 

    @Override 
    public boolean onTap(GeoPoint p, MapView mapView) { 
    // Handle tapping on the overlay here 
     System.out.println("here is is clicked"); 
    // final Intent myIntent = new Intent(getApplicationContext(), Places.class); 
     new AlertDialog.Builder(context) 
       .setTitle("Title") 
      .setMessage("Beach") 
       .setPositiveButton("Yes", 
         new DialogInterface.OnClickListener() { 
         // @Override 
          public void onClick(DialogInterface dialog, int which) { 
         } 
         }) 
       .setNegativeButton("No", 
         new DialogInterface.OnClickListener() { 
         // @Override 
          public void onClick(DialogInterface dialog, int which) { 
          } 

         }).show(); 
    return true; 
    } 
} 

, 경고 대화 상자를 볼 경우 내 DrawableMapOverlay입니다 나는 yes를 누릅니다. 문제는지도를 볼 때마다 탭을 할 때마다 onTap이 호출된다는 것입니다 (지도의 관련없는 부분을 누르면 알림 대화 상자도 표시됩니다).

도움이 필요하십니까?

답변

3

int이 오버레이 항목의 색인 인 onTap(int) 방법을 재정의해야합니다. onTap(GeoPoint, MapView)의 문서에서
:

는 탭 이벤트를 처리합니다. 탭은 항목에있는 경우에만 처리되며 true를 반환하려면 onTap (int)을 재정의했습니다.

기본적으로 onTap(GeoPoint,MapView)을 사용하는 대신 onTap(int)을 사용하십시오.

0

당신이 지역에 주어진 탭 포인트 하락 여부를 확인하기 위해 region.contains(point.x, point.y)를 사용할 필요가 다음 onTap(GeoPoint,MapView)를 사용합니다.

관련 문제