在我的Maps Activity中,我有一个AsyncTask,它使用套接字与另一个程序进行通信并获取一些信息。根据该信息,我必须在地图上移动某些标记。怎么可能?
如果我只是尝试直接从backround任务中使用setPosition(),它将无法正常工作。
每个人说的标记移动与我无关,所有必要的列表,MarkerOptions等将被添加。问题是在何处进行操作,以便更新地图,并且我可以看到标记在移动(将它们放入onMapReady无效。该功能必须结束才能显示地图)。
这是背景任务:
_name = 'biblio.location'
_description = 'All librarians'
name=fields.Char()
livre = fields.Many2one('biblio.book',string='livre',required=True,domain =[('disponible','=',True)])
client = fields.Many2one('biblio.customer',string="client",required=True)
date_location =fields.Datetime(required=True)
date_retour_prevu=fields.Datetime(required=True,string="Date retour prévu")
date_retour_reelle=fields.Datetime(required=True,string="Date retour réelle")
和onMapReady方法:
class backTask extends AsyncTask<Void, Void, Void>
{
Consumer consumer;
public backTask(Consumer c)
{
this.consumer = c;
}
@Override
protected Void doInBackground(Void... voids)
{
String comm_info = consumer.Start();
StringTokenizer tok = new StringTokenizer(comm_info, "+");
int bro_port = Integer.parseInt(tok.nextToken());
String bro_ip = tok.nextToken();
//keep asking for updates
Message question = new Message("update?");
Message answer;
try
{
while(true)
{
Socket Con_sock = new Socket(InetAddress.getByName(bro_ip), bro_port);
ObjectOutputStream ask = new ObjectOutputStream(Con_sock.getOutputStream());
ObjectInputStream rep = new ObjectInputStream(Con_sock.getInputStream());
//asking
ask.writeObject(question);
ask.flush();
//get response
answer = (Message) rep.readObject();
if (answer.type == 2)
{
//No update
}
else if (answer.type == 0)
{
//got update
//move / create markers here
}
Thread.sleep(500);
}//loop
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
}//backTask END
}