java - IndoorAtlas SDK 2.0 map 未加载

标签 java android location maps indoor-positioning-system

我正在尝试在我的项目中使用 IndoorAtlas。我创建了 Activity this例如,但是当我启动 Activity 时,我什么也没看到, map 没有加载到 ImageView 中,并且 LogCat 仅显示几行。请帮忙。

我的 LogCat 带有“IndoorAtlas”过滤器:

D/IndoorAtlasActivity: onCreate/ requestLocationUpdates() called
D/IndoorAtlasActivity: onResume/ requestLocationUpdates() called
D/IACore: IndoorAtlas Android SDK
           SDK    : 2.0.2-beta-9999
           Android: 4.2.1-17
           Date   : Sat, 20 Feb 2016 22:14:41 GMT

我的XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar" />

</RelativeLayout>

我的 Activity :

  public class IndoorAtlasActivity extends AppCompatActivity {

    private static final String TAG = "IndoorAtlasActivity";

    private IALocationManager mIALocationManager;
    private IAResourceManager mResourceManager;
    private ImageView mImageView;
    private IATask<IAFloorPlan> mPendingAsyncResult = null;

    private IAResourceManager mFloorPlanManager;
    private IAFloorPlan mFloorPlan;
    private long mDownloadId;
    private DownloadManager mDownloadManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_indooratlas);

        mIALocationManager = IALocationManager.create(this);
        mImageView = (ImageView) findViewById(R.id.image);

        mIALocationManager.registerRegionListener(mRegionListener);

        mIALocationManager.requestLocationUpdates(IALocationRequest.create(), mLocationListener);
        Log.d(TAG, "onCreate/ requestLocationUpdates() called");

        mDownloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
        mIALocationManager = IALocationManager.create(this);
        mFloorPlanManager = IAResourceManager.create(this);

        /* optional setup of floor plan id
           if setLocation is not called, then location manager tries to find
           location automatically */
        final String floorPlanId = "my_floor_plan_id";
        if (!TextUtils.isEmpty(floorPlanId)) {
            final IALocation location = IALocation.from(IARegion.floorPlan(floorPlanId));
            mIALocationManager.setLocation(location);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        mIALocationManager.requestLocationUpdates(IALocationRequest.create(), mLocationListener);
        mIALocationManager.registerRegionListener(mRegionListener);
        registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
        Log.d(TAG, "onResume/ requestLocationUpdates() called");
    }

    @Override
    protected void onPause() {
        super.onPause();
        mIALocationManager.removeLocationUpdates(mLocationListener);
        mIALocationManager.unregisterRegionListener(mRegionListener);
        unregisterReceiver(onComplete);
        Log.d(TAG, "onPause/ removing requestLocationUpdates()");
    }

    @Override
    protected void onDestroy() {
        mIALocationManager.destroy();
        Log.d(TAG, "onDestroy/ destroying mIALocationManager");

        super.onDestroy();
    }

    private IALocationListener mLocationListener = new IALocationListenerSupport() {
        @Override
        public void onLocationChanged(IALocation location) {
            Log.d(TAG, "location is: " + location.getLatitude() + "," + location.getLongitude());
        }
    };

    private IARegion.Listener mRegionListener = new IARegion.Listener() {

        @Override
        public void onEnterRegion(IARegion region) {
            if (region.getType() == IARegion.TYPE_FLOOR_PLAN) {
                String id = region.getId();
                Log.d(TAG, "floorPlan changed to " + id);
                Toast.makeText(IndoorAtlasActivity.this, id, Toast.LENGTH_SHORT).show();
                fetchFloorPlan(id);
            }
        }

        @Override
        public void onExitRegion(IARegion region) {
            // leaving a previously entered region
        }

    };

    /*  Broadcast receiver for floor plan image download */
    private BroadcastReceiver onComplete = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0L);
            if (id != mDownloadId) {
                Log.w(TAG, "Ignore unrelated download");
                return;
            }
            Log.w(TAG, "Image download completed");
            Bundle extras = intent.getExtras();
            DownloadManager.Query q = new DownloadManager.Query();
            q.setFilterById(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID));
            Cursor c = mDownloadManager.query(q);

            if (c.moveToFirst()) {
                int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
                if (status == DownloadManager.STATUS_SUCCESSFUL) {
                    // process download
                    String filePath = c.getString(c.getColumnIndex(
                            DownloadManager.COLUMN_LOCAL_FILENAME));
                    showFloorPlanImage(filePath);
                }
            }
            c.close();
        }
    };

    private void showFloorPlanImage(String filePath) {
        Log.w(TAG, "showFloorPlanImage: " + filePath);
        Picasso.with(this)
                .load(filePath)
                .into(mImageView);
    }

    /**
     * Fetches floor plan data from IndoorAtlas server. Some room for cleaning up!!
     */
    private void fetchFloorPlan(String id) {
        cancelPendingNetworkCalls();
        final IATask<IAFloorPlan> asyncResult = mFloorPlanManager.fetchFloorPlanWithId(id);
        mPendingAsyncResult = asyncResult;
        if (mPendingAsyncResult != null) {
            mPendingAsyncResult.setCallback(new IAResultCallback<IAFloorPlan>() {
                @Override
                public void onResult(IAResult<IAFloorPlan> result) {
                    Log.d(TAG, "fetch floor plan result:" + result);
                    if (result.isSuccess() && result.getResult() != null) {
                        mFloorPlan = result.getResult();
                        String fileName = mFloorPlan.getId() + ".img";
                        String filePath = Environment.getExternalStorageDirectory() + "/"
                                + Environment.DIRECTORY_DOWNLOADS + "/" + fileName;
                        File file = new File(filePath);
                        if (!file.exists()) {
                            DownloadManager.Request request =
                                    new DownloadManager.Request(Uri.parse(mFloorPlan.getUrl()));
                            request.setDescription("IndoorAtlas floor plan");
                            request.setTitle("Floor plan");
                            // requires android 3.2 or later to compile
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                request.allowScanningByMediaScanner();
                                request.setNotificationVisibility(DownloadManager.
                                        Request.VISIBILITY_HIDDEN);
                            }
                            request.setDestinationInExternalPublicDir(Environment.
                                    DIRECTORY_DOWNLOADS, fileName);

                            mDownloadId = mDownloadManager.enqueue(request);
                        } else {
                            showFloorPlanImage(filePath);
                        }
                    } else {
                        // do something with error
                        if (!asyncResult.isCancelled()) {
                            Toast.makeText(IndoorAtlasActivity.this,
                                    (result.getError() != null
                                            ? "error loading floor plan: " + result.getError()
                                            : "access to floor plan denied"), Toast.LENGTH_LONG)
                                    .show();
                        }
                    }
                }
            }, Looper.getMainLooper()); // deliver callbacks in main thread
        }
    }

    private void cancelPendingNetworkCalls() {
        if (mPendingAsyncResult != null && !mPendingAsyncResult.isCancelled()) {
            mPendingAsyncResult.cancel();
        }
    }

}

最佳答案

您不需要 ImageView 来加载和显示平面图。您需要一个名为“BlueDotView”的类,您可以从此链接找到它:BlueDotView class 。如果您正确地浏览ImageViewActivity类(从创建 Activity 的位置),您将看到没有需要使用的此类 ImageView 。 ImageViewActivity 类具有以下内容:
private BlueDotView mImageView;

为了正确加载平面图,请执行以下步骤。
1. 使用 ImageViewActivity 正确交叉检查您的 Activity 。
2. 您必须将 BlueDotView 类作为单独的类。
3. 在您的activity_indooratlas XML 文件中,您应该有如下内容,这些内容来自 SDK 2.0 的 github 存储库,而不是 XML 文件中的内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.indooratlas.android.sdk.examples.imageview.BlueDotView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>
  • 确保您拥有 IndoorAtlas 网站上的 API key 和 API key ,并将其包含在您的 Android list 文件中。从 github 存储库检查 android list ,链接如下:AndroidManifest.xml
  • 关于java - IndoorAtlas SDK 2.0 map 未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35529802/

    相关文章:

    java - Java中基于属性的压缩ArrayList

    android - 如何通过单击取消单击单选按钮来动态删除 LinearLayout?

    ios - 如何在自定义 map 上显示用户位置?

    ios - 在swift中获取坐标时为零

    java - 什么设计比较好 : universal builder or several concrete methods?

    java - PMD 对接口(interface)的可变对象的引用

    android - 支持不同的语言

    android - 在刚刚完成的进度对话框中显示警报对话框android

    MySQL 8.0数据分离部署

    java - 如何将 json 字符串转换为 java 列表?