2

我有一个 Home 列表,每个 Home 都是一个带有纬度、经度、名称和描述的对象。现在我想在 android MapView 中将所有房屋视为地理点。

我在网站上搜索了一些关于的内容,并且我看到需要地图叠加层。

所以我在 SearchHome Activity 中完成了这个(即带有地图和搜索框的活动)

MapLocationOverlay mapLocationOverlay = new MapLocationOverlay(SearchHome.this, elementi, SearchHome.this.getResources().getDrawable(R.drawable.home_icon));
            overlays = mapView.getOverlays();
            overlays.add(mapLocationOverlay);

我的 MapOverlay 课程是:

public class MapLocationOverlay extends ItemizedOverlay<OverlayItem> {

   private List<Home> homeList;
   private Context context;

   public MapLocationOverlay(Context context, List<Home> homeList, Drawable marker) {
      super(boundCenterBottom(marker));
      this.context = context;
      this.homeList = homeList;
      if (homeList == null) {
          homeList = new ArrayList<Home>();
      }
      populate();
   }

   @Override
   protected OverlayItem createItem(int i) {
       Home c=homeList.get(i);
       GeoPoint point =
               new GeoPoint((int) ((Double.valueOf(c.getLatitude()) * 1e6)), (int) ((Double.valueOf(c.getLongitude()) * 1e6)));
      return new OverlayItem(point, c.getNameHouse(), null);
   }

   @Override
   public boolean onTap(final int index) {
      Home h = homelist.get(index);
      AlertDialog.Builder builder = new AlertDialog.Builder(context);
      builder.setTitle("HomeLocation")
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                     Intent i = new Intent(context, HouseDetails.class);
                     i.putExtra(HomeMapApp.index, index);
                     context.startActivity(i);
                  }
               }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                     dialog.cancel();
                  }
               });
      AlertDialog alert = builder.create();
      alert.show();

      return true; // we'll handle the event here (true) not pass to another overlay (false)
   }

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

但我不知道如何配置监听器 onTap 以使用 GeoPoint 正确处理地图中的相关 House 项目。

例如,如果我单击纽约的地理点 MyHouse,我应该获取相应 House java 对象的所有数据并将其发送到 HouseDetail 类以显示信息。

4

1 回答 1

2

我已经回答了相同类型的问题 看看我的回答很可能会回答你的问题

使用 osmdroid 覆盖项目的自定义信息气泡

于 2012-05-21T11:06:12.663 回答