我所做的是从xml文件中获取数据,然后使用Custom ItemizedOverlay添加项目。
public CustomItemizedOverlay callme(List<Places> result){
Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
latitudeE6 = result.get(i).latitude;
longitudeE6 = result.get(i).longitude;
GeoPoint point = new GeoPoint(latitudeE6a, longitudeE6a);
OverlayItem overlayitem = new OverlayItem(point, result.get(i).title, result.get(i).text);
CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable);
itemizedOverlay.addOverlay(overlayitem);//add point
i++;
latitudeE6 =0;
longitudeE6 =0;
return itemizedOverlay;
}
当我在UI线程上时,我使用while()循环来打印:
int j=0;
List<Overlay> mapOverlays = mapView.getOverlays();
while( j < 5 ) {
test1 = callme(result1);
mapOverlays.add(test1);
j++;
}
MapController mapController = mapView.getController();
mapController.setZoom(12);
只有五个项目,循环停止而j < 5。 问题是它只显示xml数据中的最后一项。
答案 0 :(得分:2)
步骤1: 添加这个java文件..
public class MapItemizedOverlay extends ItemizedOverlay<OverlayItem>
{
public static boolean isRouteSelecting;
public static ArrayList<GeoPoint> geoPoints;
private GeoPoint geoPoint_;
private ArrayList<OverlayItem> overlayItems_ = new ArrayList<OverlayItem>();
public MapItemizedOverlay(Drawable defaultMarker)
{
super(boundCenterBottom(defaultMarker));
// TODO Auto-generated constructor stub
}
public void addOverlay(OverlayItem overlayItem)
{
overlayItems_.add(overlayItem);
populate();
}
@Override
protected OverlayItem createItem(int i)
{
// TODO Auto-generated method stub
return overlayItems_.get(i);
}
@Override
public int size()
{
// TODO Auto-generated method stub
return overlayItems_.size();
}
}
步骤2: 进入MapActivity ...(oncreate)
mapItemizedOverlay_ = new MapItemizedOverlay(drawable_);
for(int i = 0; i < yourList.size(); i++)
{
GeoPoint geoPoint = new GeoPoint(Latitude, Longitude);
OverlayItem overlayItem = new OverlayItem(geoPoint, busStop.getStopName(), "");
mapItemizedOverlay_.addOverlay(overlayItem);
}
drawable_ = this.getResources().getDrawable(R.drawable.ic_launcher);
mapView_.getOverlays().add(mapItemizedOverlay_);
答案 1 :(得分:1)
您在int i
方法
callme(List<Places> result)
的循环
<强>更新强>
List<Overlay> mapOverlays = mapView.getOverlays();
for(int i=0;i<result1.size();i++)
{
Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
latitudeE6 = result1.get(i).latitude;
longitudeE6 = result1.get(i).longitude;
GeoPoint point = new GeoPoint(latitudeE6a,longitudeE6a);
OverlayItem overlayitem = new OverlayItem(point, result1.get(i).title, result1.get(i).text);
CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable);
itemizedOverlay.addOverlay(overlayitem); //add point
mapOverlays.add(itemizedOverlay);
}
latitudeE6 =0;
longitudeE6 =0;
MapController mapController = mapView.getController();
mapController.setZoom(12);
使用上面的代码删除你的代码你发布了什么问题,让mek现在发生了什么..