Android 百度地图开发 全景图SDK的使用

参考了百度地图sdk官方文档,和博客https://blog.csdn.net/lonely0512/article/details/84821288

我的百度SDK是现在最新的5.3.0版本,AndroidSDK 7.1.1 好了 不说废话 直接上代码
…….
1.在AndroidMaifest.xml文件中加入权限
<supports-screens
android:anyDensity=”true”
android:largeScreens=”true”
android:normalScreens=”false”
android:resizeable=”true”
android:smallScreens=”true” />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
    android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
    tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

2.写一个类继承Application

package com.example.immedsee.activity;

import com.baidu.lbsapi.BMapManager;
import com.baidu.lbsapi.MKGeneralListener;
import android.app.Application;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class PanorApplication extends Application {
    private static PanorApplication mInstance = null;
    public BMapManager mBMapManager = null;

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
        initEngineManager(this);
    }

    public void initEngineManager(Context context) {
        if (mBMapManager == null) {
            mBMapManager = new BMapManager(context);
        }

        if (!mBMapManager.init(new MyGeneralListener())) {
            Toast.makeText(
                    PanorApplication.getInstance().getApplicationContext(),
                    "BMapManager  初始化错误!", Toast.LENGTH_LONG).show();
        }
        Log.d("ljx", "initEngineManager");
    }

    public static PanorApplication getInstance() {
        return mInstance;
    }

    // 常用事件监听,用来处理通常的网络错误,授权验证错误等
    static class MyGeneralListener implements MKGeneralListener {

        @Override
        public void onGetPermissionState(int iError) {
            // 非零值表示key验证未通过
            if (iError != 0) {
                // 授权Key错误:
                Toast.makeText(
                        PanorApplication.getInstance()
                                .getApplicationContext(),
                        "请在AndoridManifest.xml中输入正确的授权Key,并检查您的网络连接是否正常!error: "
                                + iError, Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(
                        PanorApplication.getInstance()
                                .getApplicationContext(), "key认证成功",
                        Toast.LENGTH_LONG).show();
            }
        }
    }
}

3.布局代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <com.baidu.lbsapi.panoramaview.PanoramaView
       android:id="@+id/panorama"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="true" />

</LinearLayout>

4.初始化BMapManager 一定要在setContentView之前

PanorApplication app = (PanorApplication) this.getApplication();
        if (app.mBMapManager == null) {
            app.mBMapManager = new BMapManager(app);
            app.mBMapManager.init(new PanorApplication.MyGeneralListener());
        }
setContentView(R.layout.activity_result_details);

5.最后就可以使用

mPanoramaView.setPanoramaByUid(resultUid,PanoramaView.PANOTYPE_STREET);

6.一定要记住!!! 在AndroidMaifest.xml文件的application中加上name属性,名字是你写的那个集成Application

 <application
        android:name=".activity.PanorApplication"
        android:allowBackup="true"
    原文作者:patch张
    原文地址: https://www.jianshu.com/p/ab785d9d875c
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞