在下面的 CustomMap.java 类中,我想自定义代码,以便我可以添加地理点数组、多个 itemisedOvelay,如 CustomMap 第 2 部分。
public class CustomMap extends MapActivity {
MapView mapView;
List<Overlay> mapOverlays;
Drawable drawable;
Drawable drawable2;
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay;
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapOverlays = mapView.getOverlays();
// first overlay
drawable = getResources().getDrawable(R.drawable.marker);
itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);
GeoPoint point = new GeoPoint((int)(51.5174723*1E6),(int)(-0.0899537*1E6));
CustomOverlayItem overlayItem = new CustomOverlayItem(point, "Tomorrow Never Dies (1997)",
"(M gives Bond his mission in Daimler car)",
"http://ia.media-imdb.com/images/M/MV5BMTM1MTk2ODQxNV5BMl5BanBnXkFtZTcwOTY5MDg0NA@@._V1._SX40_CR0,0,40,54_.jpg");
itemizedOverlay.addOverlay(overlayItem);
GeoPoint point2 = new GeoPoint((int)(51.515259*1E6),(int)(-0.086623*1E6));
CustomOverlayItem overlayItem2 = new CustomOverlayItem(point2, "GoldenEye (1995)",
"(Interiors Russian defence ministry council chambers in St Petersburg)",
"http://ia.media-imdb.com/images/M/MV5BMzk2OTg4MTk1NF5BMl5BanBnXkFtZTcwNjExNTgzNA@@._V1._SX40_CR0,0,40,54_.jpg");
itemizedOverlay.addOverlay(overlayItem2);
mapOverlays.add(itemizedOverlay);
// second overlay
drawable2 = getResources().getDrawable(R.drawable.marker2);
itemizedOverlay2 = new CustomItemizedOverlay<CustomOverlayItem>(drawable2, mapView);
GeoPoint point3 = new GeoPoint((int)(51.513329*1E6),(int)(-0.08896*1E6));
CustomOverlayItem overlayItem3 = new CustomOverlayItem(point3, "Sliding Doors (1998)",
"(interiors)", null);
itemizedOverlay2.addOverlay(overlayItem3);
GeoPoint point4 = new GeoPoint((int)(51.51738*1E6),(int)(-0.08186*1E6));
CustomOverlayItem overlayItem4 = new CustomOverlayItem(point4, "Mission: Impossible (1996)",
"(Ethan & Jim cafe meeting)",
"http://ia.media-imdb.com/images/M/MV5BMjAyNjk5Njk0MV5BMl5BanBnXkFtZTcwOTA4MjIyMQ@@._V1._SX40_CR0,0,40,54_.jpg");
itemizedOverlay2.addOverlay(overlayItem4);
mapOverlays.add(itemizedOverlay2);
final MapController mc = mapView.getController();
mc.animateTo(point2);
mc.setZoom(16);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
代码第 2 部分:
这不是代码,而是我希望如何进行更改的一些逻辑。总而言之,我尝试使 CustomMap.java 灵活,以便我可以通过数组向它添加多个点和信息。
public class CustomMap extends MapActivity {
MapView mapView;
List<Overlay> mapOverlays;
Drawable drawable;
Drawable drawable2;
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay[];
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay2[];
double[]lat,lon;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapOverlays = mapView.getOverlays();
// first overlay
drawable = getResources().getDrawable(R.drawable.marker);
itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);
GeoPoint point[] = new GeoPoint((int)(lat*1E6),(int)(lon*1E6));
CustomOverlayItem overlayItem = new CustomOverlayItem(point, "Tomorrow Never Dies (1997)",
"(M gives Bond his mission in Daimler car)",
"http://ia.media-imdb.com/images/M/MV5BMTM1MTk2ODQxNV5BMl5BanBnXkFtZTcwOTY5MDg0NA@@._V1._SX40_CR0,0,40,54_.jpg");
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
final MapController mc = mapView.getController();
mc.animateTo(point2);
mc.setZoom(16);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}