1
我在註冊某人時遇到了某些人在地圖上某處觸摸過的問題。無法從Google地圖獲取touchevent
我有這個源
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;
}
我是否正確實現了類?有誰知道如何解決這一問題?
您是否收到任何錯誤?如果是,請添加錯誤日誌,以便它很容易解決....... – Scorpion 2012-03-07 04:55:11