``您需要使用扩展覆盖类的类,例如(请注意,此代码用于获取 json 而不是 xml)
public class LocationOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();
Context context;
public LocationOverlay(Drawable marker, Context c) {
super(boundCenterBottom(marker));
// TODO Auto-generated constructor stub
populate();
context = c;
}
@Override
protected boolean onTap(int index) {
Toast.makeText(context,
"Touch on marker: \n" + overlayItemList.get(index).getTitle(),
Toast.LENGTH_LONG).show();
// code for passing storeid's
OverlayItem item = overlayItemList.get(index);
String idex = (item.getTitle());
Intent idtent = new Intent(context, StoreDetails.class);
idtent.putExtra("&", idex);
context.startActivity(idtent);
return true;
}
public void addItem(GeoPoint p, String title) {
OverlayItem newItem = new OverlayItem(p, title, null);
overlayItemList.add(newItem);
populate();
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return overlayItemList.get(i);
}
@Override
public int size() {
// TODO Auto-generated method stub
return overlayItemList.size();
}
现在只需在您显示地图的班级中,执行此操作
Double jlat = j4.getDouble("Latitude");
Double jlon = j4.getDouble("Longitude");
Log.v("Latitude", jlat + "n");
Log.v("Longitude", jlon + "n");
// Get the distance between lat long
Location locationA = new Location("point A");
locationA.setLatitude(slat);
locationA.setLongitude(slon);
Location locationB = new Location("point B");
locationB.setLatitude(jlat);
locationB.setLongitude(jlon);
distance = (int) locationA.distanceTo(locationB);
String str = " (" + String.valueOf(distance) + " meters)";
Log.v("Distance", str);
// adjust drawable params
Drawable marker = getResources().getDrawable(
android.R.drawable.star_big_on);
Drawable user = getResources().getDrawable(
android.R.drawable.arrow_down_float);
int userWidth = user.getIntrinsicWidth();
int userHeight = user.getIntrinsicHeight();
user.setBounds(0, userHeight, userWidth, 0);
int markerWidth = marker.getIntrinsicWidth();
int markerHeight = marker.getIntrinsicHeight();
marker.setBounds(0, markerHeight, markerWidth, 0);
// refernc to overlay class
LocationOverlay myItemizedOverlay = new LocationOverlay(
marker, MapActivity.this);
LocationOverlay myItemizedOverlay1 = new LocationOverlay(
user, MapActivity.this);
mapView.getOverlays().add(myItemizedOverlay);
mapView.getOverlays().add(myItemizedOverlay1);
// create geopoint for user
GeoPoint usr = new GeoPoint((int) (slat * 1e6),
(int) (slon * 1e6));
// add overlay(user) to user's location
myItemizedOverlay1.addItem(usr, "User");
mc.animateTo(usr);
并且在上面的类中,您可以在用户点击地理点时添加任何类型的处理程序..