这是我在Google地图中使用的叠加层。我添加了两个标记,并希望为这些标记添加一个监听器。下面是我的叠加类:
protected class MyLocationOverlay extends com.google.android.maps.Overlay {
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);
// Converts lat/lng-Point to OUR coordinates on the screen.
Point myScreenCoords = new Point();
mapView.getProjection().toPixels(p, myScreenCoords);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.passenger_map);
canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, null);
// canvas.drawText("I am here...", myScreenCoords.x, myScreenCoords.y, paint);
mapView.getProjection().toPixels(p1, myScreenCoords);
Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.driver_map);
canvas.drawBitmap(bmp1, myScreenCoords.x, myScreenCoords.y, null);
// canvas.drawText(" Driver : I am here...", myScreenCoords.x, myScreenCoords.y, paint);
return true;
}
答案 0 :(得分:1)
你需要使用ItemizedOverlay类来点击标记。因为你需要覆盖
onTap()或onTouch()
用于标记和地图
public boolean onTap (final GeoPoint p, final MapView mapView){
boolean tapped = super.onTap(p, mapView);
if (tapped){
//do what you want to do when you hit an item
}
else{
//do what you want to do when you DONT hit an item
}
return true;
}
//你必须拥有这种方法,即使它没有明显做任何事情
@覆盖 protected boolean onTap(int index){ 返回true; }
这是链接
http://developer.android.com/guide/tutorials/views/hello-mapview.html
OnTap() event on map is not fired