我有可以显示叠加的活动。此叠加层具有从网络获取的标记。
如何为此标记实现URL的延迟加载?
Thx,Igor
答案 0 :(得分:3)
您需要做的是创建一个AsyncTask来检索您的数据。一旦异步任务执行并且您拥有数据,UI线程将调用onPostExecute()。在onPostExecute()方法中,您将数据添加到地图视图中,与示例android代码中的数据相同。
这是一个最完整的例子。你应该能够填补这个洞。
public class SomeActivity extends MapActivity {
private MapView mYourMapView;
protected void onCreate(Bundle yourbundle){
super.onCreate(yourbundle);
setContentView(R.layout.yourcontentview);
mYourMapView = (MapView)findViewById(R.id.yourmapviewid);
GetYourDataTask task = new GetYourDataTask(mYourMapView);
task.execute();
}
}
public class GetYourDataTask extends AsyncTask<Void, Void, Void>{
private MapView mView;
private List<Items> mYourItemsFromInternetSource;
public GetYourDataTask(MapView view){
this.mView = view;
}
protected Void doInBackground(Void... params){
.....get some data from internets
mYourItemsfromInternetSoruce = something you got from internet;
return null;
}
protected Void onPostExecute(){
YourOverlay overlay = new YourOverlay(mYourItemsFromInterSource);
mView.getOverlays().add(overlay);
}
}
public YourOverlay extends ItemizedOverlay<OverlayItem>{
private List<OverlayItem> mItems;
public YourOverlay(List<Item> itemsFromInternet)[
super(boundCenterBottom(someContext.getResources().getDrawable(R.drawable.map_pin)));
//for your items create overlay items then
List<OverlayItem> createdItems = someConvertFunction(itemsFromInternet);
for(OverlayItem item: createdItems){
mItems.add(item);
populate();
}
}
}