GoogleMap.animateCamera不适用于后台线程 [英] GoogleMap.animateCamera not working on background thread

查看:115
本文介绍了GoogleMap.animateCamera不适用于后台线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在后台线程中更改相机焦点?
缩放在线程中正常工作,但不改变坐标。
如果线程中没有使用,也可以更改坐标,但我打算使用延迟,因此它需要存在。

  @Override 
public void run(){

if(points.size()> 0){
Polyline line = map.addPolyline(new PolylineOptions( )
.addAll(points)
.width(5)
.color(Color.RED));
System.out.println(points.get(0).toString());
map.animateCamera(CameraUpdateFactory.newLatLng(points.get(0)));
map.animateCamera(CameraUpdateFactory.zoomTo(14));
}
}


解决方案

因为您可能没有在主UI线程中运行此功能。

更改

  map.animateCamera(CameraUpdateFactory.newLatLng(points.get(0))); 
map.animateCamera(CameraUpdateFactory.zoomTo(14));

  runOnUiThread(new Runnable(){
$ b $ @Override
public void run(){
map.animateCamera(CameraUpdateFactory.newLatLng(points.get(0)) );
map.animateCamera(CameraUpdateFactory.zoomTo(14));
}
});


How do I change the camera focus inside a background thread? The zoom works fine in the thread, but changing the coordinates doesn't. Also changing the coordinates works if not used in the thread, but I intend on using delays so It needs to be in there.

@Override
        public void run() {

            if (points.size() > 0){
                Polyline line = map.addPolyline(new PolylineOptions()
                        .addAll(points)
                        .width(5)
                        .color(Color.RED));
                System.out.println(points.get(0).toString());
                map.animateCamera(CameraUpdateFactory.newLatLng(points.get(0)));
                map.animateCamera(CameraUpdateFactory.zoomTo(14));
            }
        }

解决方案

Probably because you may not be running this in a main UI thread

Change

map.animateCamera(CameraUpdateFactory.newLatLng(points.get(0)));
map.animateCamera(CameraUpdateFactory.zoomTo(14));

to

runOnUiThread(new Runnable() {

                     @Override
                     public void run() {
                            map.animateCamera(CameraUpdateFactory.newLatLng(points.get(0)));
                            map.animateCamera(CameraUpdateFactory.zoomTo(14));
                     }
                    });

这篇关于GoogleMap.animateCamera不适用于后台线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆