これは私の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;
}
これが私のDrawableMapOverlayです
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;
}
}
マーカーをタップするときに、アラートダイアログを表示し、[はい]を押したら何かを実行します。問題は、マーカーだけでなく、Tapを実行するたびにonTapが呼び出されることです(マップの無関係なポイントを押すと、アラートダイアログも表示されます)。
何か助けはありますか?