gpt4 book ai didi

Android itemizedOverlay 的 onTap Action 被覆盖

转载 作者:太空狗 更新时间:2023-10-29 14:30:57 26 4
gpt4 key购买 nike

我有一个类:

class MapItemizedOverlay extends com.google.android.maps.ItemizedOverlay<OverlayItem> { 
private Context context;
private ArrayList items = new ArrayList();

public MapItemizedOverlay(Context aContext, Drawable marker) {
super(boundCenterBottom(marker));
context = aContext;
}

public void addOverlayItem(OverlayItem item) {
items.add(item);
populate();
}

@Override
protected OverlayItem createItem(int i) {
return (OverlayItem) items.get(i);
}

@Override
public int size() {
return items.size();
}

@Override
protected boolean onTap(int index) {
OverlayItem item = (OverlayItem) items.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}

@Override
public boolean onTap (final GeoPoint p, final MapView mapView) {
Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(p.getLatitudeE6() / 1E6,
p.getLongitudeE6() / 1E6, 1);
String address = "";
if (addresses.size() > 0) {
for (int i=0; i<addresses.get(0).getMaxAddressLineIndex(); i++)
address += addresses.get(0).getAddressLine(i) + "\n";
}
address.cancel();
address.setText(address);
address.show();
}
catch (IOException e) {
e.printStackTrace();
}
return true;
}
}

我使用以下函数在 map 上添加一些叠加层:

private void initialiseOverlays() {
// Create an ItemizedOverlay to display a list of markers
Drawable defaultMarker = getResources().getDrawable(R.drawable.marker);
MapItemizedOverlay mapItemizedOverlay = new MapItemizedOverlay(this, defaultMarker);

mapItemizedOverlay.addOverlayItem(new OverlayItem(new GeoPoint((int) (12.345678 * 1E6), (int) (23.456789 * 1E6)), "Point 1", "some-random-text"));
mapItemizedOverlay.addOverlayItem(new OverlayItem(new GeoPoint((int) (89.012345 * 1E6), (int) (67.890123 * 1E6)), "Point number 2", "more-random-text"));
// Add the overlays to the map
mapView.getOverlays().add(mapItemizedOverlay);
}

如果只定义了一个 onTap 函数,则一切正常 - 如果我在 map 上的某处单击,我可以获得地址,或者如果我单击该地点上的图标,我可以获得包含该地点标题和内容的对话框.但我想让这两个功能一起工作,应用程序检测点击是在 map 上的空白位置还是在标记(可绘制集)上并显示它的信息。我怎样才能做到这一点?

最佳答案

找到答案 - 必须包括:

if(super.onTap(p, mapView)) {
return true;
}

public boolean onTap (final GeoPoint p, final MapView mapView) 函数的开头。

关于Android itemizedOverlay 的 onTap Action 被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6995442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com