gpt4 book ai didi

java - IndoorAtlas SDK 2.0 map 未加载

转载 作者:太空宇宙 更新时间:2023-11-04 12:54:29 26 4
gpt4 key购买 nike

我正在尝试在我的项目中使用 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/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com