当有人触摸地图上的某个地方时,我正在注册一些问题。
我有这个来源
public class GMapsActivity extends MapActivity {
private MapView mapView;
private static final int latitudeE6 = 37985339;
private static final int longitudeE6 = 23716735;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.map_view);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);
GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
OverlayItem overlayitem = new OverlayItem(point, "Hello", "I'm in Athens, Greece!");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
//mapOverlays.add(TouchOverlay);
MapController mapController = mapView.getController();
mapController.animateTo(point);
mapController.setZoom(6);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
class MapOverlap extends com.google.android.maps.Overlay {
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
if (event.getAction() == 1){
GeoPoint p = mapView.getProjection().fromPixels( (int) event.getX(), (int) event.getY());
Toast.makeText(getBaseContext(), p.getLatitudeE6()/1E6 + "," + p.getLongitudeE6()/1E6 , Toast.LENGTH_SHORT).show();
}
return false;
}
}
}
和CustomItemizedOverlay
public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context context;
public CustomItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public CustomItemizedOverlay(Drawable defaultMarker, Context context) {
this(defaultMarker);
this.context = context;
}
@Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}
@Override
public int size() {
return mapOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mapOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
this.populate();
}
}
我添加了(但它似乎没有做任何事情)
class MapOverlap extends com.google.android.maps.Overlay {
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
if (event.getAction() == 1){
GeoPoint p = mapView.getProjection().fromPixels( (int) event.getX(), (int) event.getY());
Toast.makeText(getBaseContext(), p.getLatitudeE6()/1E6 + "," + p.getLongitudeE6()/1E6 , Toast.LENGTH_SHORT).show();
}
return false;
}
我是否正确实施了课程?有谁知道如何解决这个问题?
答案 0 :(得分:0)
在你的第二个构造函数中,你缺少这行代码:
super(boundCenterBottom(defaultMarker));
而不是:
this(defaultMarker);