我已经定义了地图叠加层,我可以毫无问题地显示标记。我现在正试图在点击一个时发生一些事情,但事件似乎永远不会发生。我确定我错过了一些明显的东西......
public class MapBlobCollection extends ItemizedOverlay<OverlayItem> {
@SuppressWarnings("serial")
public class ItemTappedEvent extends EventObject
{
public ItemTappedEvent(int itemIndex) {
super(itemIndex);
}
}
private ArrayList<OverlayItem> myOverlays ;
public MapBlobCollection(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
myOverlays = new ArrayList<OverlayItem>();
populate();
}
public void addOverlay(OverlayItem overlay){
myOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return myOverlays.get(i);
}
// Removes overlay item i
public void removeItem(int i){
myOverlays.remove(i);
populate();
}
// Returns present number of items in list
@Override
public int size() {
return myOverlays.size();
}
public void addOverlayItem(OverlayItem overlayItem) {
myOverlays.add(overlayItem);
populate();
}
public void addOverlayItem(int lat, int lon, String title) {
try {
GeoPoint point = new GeoPoint(lat, lon);
OverlayItem overlayItem = new OverlayItem(point, title, null);
addOverlayItem(overlayItem);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
@Override
protected boolean onTap(int index) {
super.onTap(index);
Log.d("TESTING","Triggering tap event on " + Integer.toString(index));
EventManager.triggerEvent(this, new ItemTappedEvent(index));
return true;
}
}
基本上,不会写入调试日志条目,并且不会触发事件。
另外,我的mapview本身并没有平移(应该没有任何额外的代码吗?),尽管设置了setBuitInZoomControls(true),但这些也没有出现......所以也许mapview本身就是有错?
mapview在布局中定义为:
<com.google.android.maps.MapView
android:id="@+id/indexMapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="@string/mapskey_release"/>
我并没有压倒任何抽奖活动或任何事情......
答案 0 :(得分:1)
我相信你需要添加
android:clickable="true"
到你的mapview
答案 1 :(得分:0)
尝试将超级功能移到最后:
@Override
protected boolean onTap(int index) {
Log.d("TESTING","Triggering tap event on " + Integer.toString(index));
EventManager.triggerEvent(this, new ItemTappedEvent(index));
return super.onTap(index);
}