Java 在后台线程中调用GoogleMap

Java 在后台线程中调用GoogleMap,java,android,google-maps,Java,Android,Google Maps,在后台线程中调用下面的代码行时出错 LatLng latlng = mMap.getProjection().getVisibleRegion().latLngBounds.getCenter(); 错误 com.google.maps.api.android.lib6.common.apiexception.c: Not on the main thread 我想在后台线程上处理与地图相关的内容,这样UI线程中就没有延迟,当我获取位置时,我会有一点延迟 @Override

在后台线程中调用下面的代码行时出错

LatLng latlng = mMap.getProjection().getVisibleRegion().latLngBounds.getCenter();
错误

com.google.maps.api.android.lib6.common.apiexception.c: Not on the main thread
我想在后台线程上处理与地图相关的内容,这样UI线程中就没有延迟,当我获取位置时,我会有一点延迟

        @Override
        public void onCameraIdle() {

        LatLng latlng = mMap.getProjection().getVisibleRegion().latLngBounds.getCenter();
        String x = "";
        try {
            Geocoder geo = new Geocoder(mActivity, Locale.getDefault());
            List<Address> addresses = geo.getFromLocation(latlng.latitude, latlng.longitude, 1);
            if (addresses.isEmpty()) {
                Log.e("CameraMove", "Waiting for Location.");
            } else {
                if (addresses.size() > 0) {
                    currentLocationCityCountry.setText(addresses.get(0).getLocality() );
                }
            }
        } catch (Exception c) {
            Log.e("CameraMove", "Error Location data not fetched   " + c.getMessage());
        }
    }
@覆盖
公共无效OnCameradile(){
LatLng LatLng=mMap.getProjection().getVisibleRegion().latLngBounds.getCenter();
字符串x=“”;
试一试{
Geocoder geo=新的Geocoder(mActivity,Locale.getDefault());
列表地址=geo.getFromLocation(latlng.latitude,latlng.longitude,1);
if(addresses.isEmpty()){
Log.e(“CameraMove”,“等待定位”);
}否则{
如果(地址.size()>0){
currentLocationCityCountry.setText(addresses.get(0.GetLocation());
}
}
}捕获(例外c){
Log.e(“CameraMove”,“未获取错误位置数据”+c.getMessage());
}
}
我正在获得locationonCameraIdle方法,如果有人帮助我如何在后台线程中获取位置,我将不胜感激

LatLng latlng = mMap.getProjection().getVisibleRegion().latLngBounds.getCenter();