我目前正在使用mapquest进行MapView,并且需要向地点添加叠加层。目前我的MapView正在运行,但叠加层不会出现。有关如何解决的任何想法?还可以在叠加层上创建onClick以将我带到ListView吗?谢谢提前!!
我的主要活动
public class QMapsActivity extends MapActivity {
protected MapView map;
AnnotationView annot;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutId());
init();
annot = new AnnotationView(map);
}
protected void init() {
// TODO Auto-generated method stub
this.setupMapView();
}
protected void setupMapView() {
// set the zoom level, center point and enable the default zoom controls
map = (MapView) findViewById(R.id.map);
map.getController().setZoom(16);
map.getController().setCenter(new GeoPoint(1.309503,103.777793));
map.setBuiltInZoomControls(true);
}
protected int getLayoutId() {
return R.layout.main;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
我的叠加课程
public class QPoiOverlay extends QMapsActivity{
protected void init() {
super.init();
setupMapView();
}
protected void addPoiOverlay() {
// TODO Auto-generated method stub
Drawable icon = getResources().getDrawable(R.drawable.location_marker);
final DefaultItemizedOverlay poiOverlay = new DefaultItemizedOverlay(icon);
OverlayItem loc1 = new OverlayItem(new GeoPoint (1.308763,103.777321), "area","area");
poiOverlay.addItem(loc1);
OverlayItem loc2 = new OverlayItem(new GeoPoint (1.309498,103.777101), "area","area");
poiOverlay.addItem(loc2);
OverlayItem loc3 = new OverlayItem(new GeoPoint (1.311531,103.778318), "area","area");
poiOverlay.addItem(loc3);
OverlayItem loc4 = new OverlayItem(new GeoPoint (1.308071,103.77841), "area","area");
poiOverlay.addItem(loc4);
poiOverlay.setOnFocusChangeListener(new ItemizedOverlay.OnFocusChangeListener() {
@Override
public void onFocusChanged(ItemizedOverlay Overlay, OverlayItem newFocus) {
// when focused item changes, recenter map and show info
map.getController().animateTo(newFocus.getPoint());
Toast.makeText(map.getContext().getApplicationContext(), newFocus.getTitle() + ": " +
newFocus.getSnippet(), Toast.LENGTH_SHORT).show();
int lastTouchedIndex = poiOverlay.getLastFocusedIndex();
if(lastTouchedIndex>-1){
OverlayItem tapped = poiOverlay.getItem(lastTouchedIndex);
annot.showAnnotationView(tapped);
}
}
});
map.getOverlays().add(poiOverlay);
map.invalidate();
}
}