【问题标题】:IndoorAtlas SDK 2.0 maps not loadingIndoorAtlas SDK 2.0 地图未加载
【发布时间】:2016-02-20 22:22:01
【问题描述】:

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

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

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();
        }
    }

}

【问题讨论】:

    标签: java android location maps indoor-positioning-system


    【解决方案1】:

    您不需要图像视图来加载和显示平面图。你需要一个名为“BlueDotView”的类,你可以从这个链接中找到它:BlueDotView class。如果你正确地浏览了 ImageViewActivity 类(从你创建活动的地方),你会看到没有需要使用的图像视图。 ImageViewActivity 类具有以下内容:
    private BlueDotView mImageView;

    为了正确加载平面图,请执行以下步骤。
    1. 使用 ImageViewActivity 正确交叉检查您的活动。
    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>
    
    1. 确保您有来自 IndoorAtlas 网站的 api 密钥和 api 密钥并包含在您的 android 清单文件中。从 github 仓库查看 android manifest,这里是链接:AndroidManifest.xml

    【讨论】:

    • 我已经从示例中复制了BlueDotView 类和ImageViewActivity,但仍然有没有地图的白屏:(
    • 您是否在 IndoorAtlas 网站上上传了平面图并进行了任何类型的地图绘制过程?如果您的回答是肯定的,那么请检查您的 android 清单并删除您在 activity_indooratlas xml 文件中的内容,并将其替换为我在上面的答案中提供的代码。在该 XML 代码中,您需要使用自己的包名称,该名称随后将以 Yourpackagename.BlueDotView 结尾。您可以从此链接获得更多帮助:docs.indooratlas.com/android
    • 我已经在 IndoorAtlas 服务器上上传了 .png,但我还没有完成映射过程。我认为示例中的代码会从服务器加载 .png 图像。
    • 也许做一些映射,也许它可以帮助你在你的应用程序中获取地图。
    • 好的。我会尝试映射。感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 1970-01-01
    • 2015-04-22
    相关资源
    最近更新 更多