Android 如何为地图上的每个检波器设置具有相关活动的多个地震点
我有一个家的列表,每个家都是一个带有纬度、经度、名称和描述的对象。 现在,我想在android MapView中将所有家庭视为地理点 我在网站上搜索了一些关于的东西,我发现需要一个地图覆盖 因此,我在SearchHome活动(即带有地图和搜索框的活动)中完成了这项工作 我的MapOverlay类是:Android 如何为地图上的每个检波器设置具有相关活动的多个地震点,android,google-maps,geolocation,android-mapview,android-maps,Android,Google Maps,Geolocation,Android Mapview,Android Maps,我有一个家的列表,每个家都是一个带有纬度、经度、名称和描述的对象。 现在,我想在android MapView中将所有家庭视为地理点 我在网站上搜索了一些关于的东西,我发现需要一个地图覆盖 因此,我在SearchHome活动(即带有地图和搜索框的活动)中完成了这项工作 我的MapOverlay类是: public class MapLocationOverlay extends ItemizedOverlay<OverlayItem> { private List<Ho
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();
}
}
公共类MapLocationOverlay扩展了ItemizeOverlay{
私人名单家庭名单;
私人语境;
公共MapLocationOverlay(上下文上下文、列表主列表、可绘制标记){
super(boundCenterBottom(marker));
this.context=上下文;
this.homeList=homeList;
if(homeList==null){
homeList=新的ArrayList();
}
填充();
}
@凌驾
受保护的OverlayItem createItem(int i){
Home c=homeList.get(i);
地质点=
新的地理点((int)((Double.valueOf(c.getLatitude())*1e6)),(int)((Double.valueOf(c.getLatitude())*1e6));
返回新的OverlayItem(point,c.getNameHouse(),null);
}
@凌驾
公共布尔onTap(最终整数索引){
Home h=homelist.get(索引);
AlertDialog.Builder=新建AlertDialog.Builder(上下文);
builder.setTitle(“HomeLocation”)
.setPositiveButton(“是”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框,int-id){
意图i=新意图(上下文、housedestails.class);
i、 putExtra(HomeMapApp.index,index);
背景。起始触觉(i);
}
}).setNegativeButton(“否”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框,int-id){
dialog.cancel();
}
});
AlertDialog alert=builder.create();
alert.show();
return true;//我们将在此处处理事件(true)而不是传递给另一个覆盖(false)
}
@凌驾
公共整数大小(){
返回homeList.size();
}
}
但我不知道如何配置listener onTap以正确处理地图中与GeoPoint相关的房屋项目。
例如,如果我单击纽约的地理点MyHouse,我应该获得相应House java对象的所有数据,并将其发送到House Detail类以显示信息。我已经回答了相同类型的问题,请查看我的答案,很可能它会回答您的问题
“但不起作用”——会发生什么?从那以后你试过什么?Ok还不清楚。现在我已经编辑了我的问题以了解更多细节。谢谢,现在我已经编辑了我的问题,你能给我更多细节吗?
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();
}
}