I have a list of Home, each Home is an object with latitude, longitude, name and description. Now I want to view all homes as geopoint in the android MapView.
I have searched in the site for something about, and I have seen that need a map overlay.
So I have done this in the SearchHome Activity (that is the activity with the map and the search box)
MapLocationOverlay mapLocationOverlay = new MapLocationOverlay(SearchHome.this, elementi, SearchHome.this.getResources().getDrawable(R.drawable.home_icon));
overlays = mapView.getOverlays();
overlays.add(mapLocationOverlay);
My MapOverlay class is:
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();
}
}
But I don't know how to configure the listener onTap to handle properly the related House item in the map with the GeoPoint.
For example If I click on the geopoint MyHouse in New York I should get all the data of the respective House java object and send it to HouseDetail class tho show the info.