尝试通过其SDK和示例使用“室内图集”

时间:2019-05-04 05:33:45

标签: android google-maps indoor-positioning-system google-indoor-maps

我一直在尝试从其SDK文档中使用IndoorAtlas https://indooratlas.freshdesk.com/support/solutions/articles/36000051242-fetching-floor-plan-images-with-android

但是某些变量未在此处初始化,它们引发了空对象引用异常。

我的MainActivity.java

public class MainActivity extends AppCompatActivity {
    IALocationManager mIALocationManager;
    private IAResourceManager mResourceManager;
    private ImageView mFloorPlanImage;
    IATask<IAFloorPlan> mPendingAsyncResult = new IATask<IAFloorPlan>() {
        @Override
        public void cancel() {

        }

        @Override
        public boolean isCancelled() {
            return false;
        }

        @Override
        public IAResult<IAFloorPlan> get() {
            return null;
        }

        @Override
        public void setCallback(IAResultCallback<IAFloorPlan> iaResultCallback, @Nullable Looper looper) {

        }
    };
    private ImageView imageview;
    private IARegion.Listener mRegionListener = new IARegion.Listener() {
        @Override
        public void onEnterRegion(IARegion region) {
            if (region.getType() == IARegion.TYPE_FLOOR_PLAN) {
                fetchFloorPlan(region.getId());
            }
        }

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

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        mIALocationManager = IALocationManager.create(this);
        mResourceManager = new IAResourceManager.create(getApplicationContext());
        mIALocationManager.registerRegionListener(mRegionListener);
        imageview = findViewById(R.id.ImageView);
        fetchFloorPlan("78980b5a-4a9e-41ff-a949-809b5b77c258");
        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }
    private void handleFloorPlanChange(IAFloorPlan newFloorPlan) {
        Picasso.get().load(newFloorPlan.getUrl()).into(imageview);
    }
    private void fetchFloorPlan(String id) {
        // Cancel pending operation, if any
        if (mPendingAsyncResult != null && !mPendingAsyncResult.isCancelled()) {
            mPendingAsyncResult.cancel();
        }
        mPendingAsyncResult = mResourceManager.fetchFloorPlanWithId(id);
        if (mPendingAsyncResult != null) {
            mPendingAsyncResult.setCallback(new IAResultCallback<IAFloorPlan>() {
                @Override
                public void onResult(IAResult<IAFloorPlan> result) {
                    Log.d("Humza Yunas", "onResult: " + result);

                    if (result.isSuccess()) {
                        handleFloorPlanChange(result.getResult());
                    } else {
                        // do something with error
                        Toast.makeText(MainActivity.this,
                                "loading floor plan failed: " + result.getError(), Toast.LENGTH_LONG)
                                .show();
                    }
                }
            }, Looper.getMainLooper()); // deliver callbacks in main thread
        }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

当我尝试修复那些错误时,没有图像加载,什么也不会发生。 之后,我从GitHub存储库尝试了他们的示例 https://github.com/IndoorAtlas/android-sdk-examples 在那里我尝试运行ImageView Activity会引发错误 mIAFloor是空对象引用。 任何帮助将不胜感激。这是我的大学任务,我要做的是从计划中获取该图像并浏览其文档以及所有不起作用的内容。

0 个答案:

没有答案