java在后台线程中调用googlemap

3j86kqsm  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(231)

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

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

错误

com.google.maps.api.android.lib6.common.apiexception.c: Not on the main thread

我想在后台线程上处理与Map相关的东西,这样在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());
        }
    }

我得到的位置oncameraidle方法,我感谢如果有人帮助我,我如何才能在后台线程中获取位置

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题