首先在 15 秒内更新地图,像这样在计时器中调用 AsynchTask,
public void AsynchTaskTimer() {
final Handler handler = new Handler();
Timer timer = new Timer();
TimerTask timer = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
try {
new YourAsynchTask().execute();
} catch (Exception e) {
// TODO Auto-generated catch block
}
}
});
}
};
timer.schedule(timer, 0, 15000); //execute in every 15sec
}
呼入。AsynchTaskTimer()
_ 中onCreate()
取消。timer
onDestroy()
现在在YourAsynchTask()
调用 webservice 中doInBackground
,从 webservice 获取标记数据填充标记对象的 ArrayList,并将标记对象的 ArrayList 传递给显示标记的方法。像这样
private class YourAsynchTask extends AsyncTask<String, Void, Integer> {
ArrayList<MarkerObject> markerArrList= new ArrayList<MarkerObject>();
markerArrList.clear();
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(YourMapFragActivity.this, "Wait...",
"Loading");
progressDialog.setMessage("Please Wait");
progressDialog.show();
super.onPreExecute();
}
@Override
protected Integer doInBackground(String... params) {
markerArrList=getMapMarkerDataFromWebservice();
return 1;
}
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
showMarkerLocationOnMap(markerArrList);
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
}
showMarkerLocationOnMap
从中获取一一标记数据markerArrList
并显示在map
希望这对您有所帮助。