Commit a9de60d8 authored by Administrator's avatar Administrator

升级百度地图api版本

parent aff2b4c3
......@@ -9,7 +9,7 @@ android {
versionCode 20200825
versionName "v1.0.0"
ndk {
abiFilters "armeabi-v7a"//, "arm64-v8a", "x86","arm64-v8a","x86_64"
abiFilters "armeabi-v7a", "arm64-v8a"//, "x86","arm64-v8a","x86_64"
}
}
buildTypes {
......@@ -20,8 +20,9 @@ android {
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
jniLibs.srcDir 'libs'
}
}
lintOptions {
......@@ -31,8 +32,9 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation fileTree(include: ['*.aar'], dir: 'libs')
provided files('jar/XposedBridgeApi-54.jar')
compile files('libs/BaiduLBS_Android.jar')
// implementation(name: 'BaiduLBS_aar_android', ext: 'aar')
// jniLibs.srcDir 'src/main/jniLibs'
implementation 'com.android.support:appcompat-v7:28.0.0'
//implementation 'com.android.support.constraint:constraint-layout:2.0.0-rc1'
......
......@@ -91,24 +91,24 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
PermissionUtil.requestPermissions(this,
new String[]{
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_FINE_LOCATION},
99);
// PermissionUtil.requestPermissions(this,
// new String[]{
// Manifest.permission.READ_PHONE_STATE,
// Manifest.permission.WRITE_EXTERNAL_STORAGE,
// Manifest.permission.ACCESS_FINE_LOCATION},
// 99);
super.onCreate(savedInstanceState);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (PermissionUtil.checkPermission(this, Manifest.permission.READ_PHONE_STATE)
== PackageManager.PERMISSION_GRANTED) {
// 在使用 SDK 各组间之前初始化 context 信息,传入 ApplicationContext
SDKInitializer.initialize(this);
} else {
Toast.makeText(this, "没有权限,无法工作", Toast.LENGTH_SHORT).show();
}
// if (PermissionUtil.checkPermission(this, Manifest.permission.READ_PHONE_STATE)
// == PackageManager.PERMISSION_GRANTED) {
// // 在使用 SDK 各组间之前初始化 context 信息,传入 ApplicationContext
// SDKInitializer.initialize(this);
// } else {
// Toast.makeText(this, "没有权限,无法工作", Toast.LENGTH_SHORT).show();
// }
}
@Override
......
package top.littlerich.virtuallocation.common;
import android.Manifest;
import android.app.Application;
import android.content.pm.PackageManager;
import android.app.Service;
import android.os.Vibrator;
import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import top.littlerich.virtuallocation.model.Gps;
import top.littlerich.virtuallocation.util.PermissionUtil;
import top.littlerich.virtuallocation.service.LocationService;
/**
* Created by xuqingfu on 2017/4/15.
*/
public class AppApplication extends Application {
public LocationService locationService;
public Vibrator mVibrator;
/**
* 全局GPS
......@@ -26,11 +29,13 @@ public class AppApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
if (PermissionUtil.checkPermission(this, Manifest.permission.READ_PHONE_STATE)
== PackageManager.PERMISSION_GRANTED) {
// 在使用 SDK 各组间之前初始化 context 信息,传入 ApplicationContext
SDKInitializer.initialize(this);
}
/***
* 初始化定位sdk,建议在Application中创建
*/
locationService = new LocationService(getApplicationContext());
mVibrator = (Vibrator) getApplicationContext().getSystemService(Service.VIBRATOR_SERVICE);
SDKInitializer.initialize(getApplicationContext());
SDKInitializer.setCoordType(CoordType.BD09LL);
}
}
\ No newline at end of file
......@@ -39,7 +39,7 @@ public class MapClickListener implements BaiduMap.OnMapClickListener {
* @return
*/
@Override
public boolean onMapPoiClick(MapPoi mapPoi) {
return false;
public void onMapPoiClick(MapPoi mapPoi) {
// return false;
}
}
package top.littlerich.virtuallocation.service;
import android.content.Context;
import android.webkit.WebView;
import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.location.LocationClientOption.LocationMode;
/**
* 定位服务LocationClient 相关
*
* @author baidu
*/
public class LocationService {
private static LocationClient client = null;
private static LocationClientOption mOption;
private static LocationClientOption DIYoption;
private Object objLock;
/***
* 初始化 LocationClient
*
* @param locationContext
*/
public LocationService(Context locationContext) {
objLock = new Object();
synchronized (objLock) {
if (client == null) {
client = new LocationClient(locationContext);
client.setLocOption(getDefaultLocationClientOption());
}
}
}
/***
* 注册定位监听
*
* @param listener
* @return
*/
public boolean registerListener(BDAbstractLocationListener listener) {
boolean isSuccess = false;
if (listener != null) {
client.registerLocationListener(listener);
isSuccess = true;
}
return isSuccess;
}
public void unregisterListener(BDAbstractLocationListener listener) {
if (listener != null) {
client.unRegisterLocationListener(listener);
}
}
/**
* @return 获取sdk版本
*/
public String getSDKVersion() {
if (client != null) {
String version = client.getVersion();
return version;
}
return null;
}
/***
* 设置定位参数
*
* @param option
* @return isSuccessSetOption
*/
public static boolean setLocationOption(LocationClientOption option) {
boolean isSuccess = false;
if (option != null) {
if (client.isStarted()) {
client.stop();
}
DIYoption = option;
client.setLocOption(option);
}
return isSuccess;
}
/**
* 开发者应用如果有H5页面使用了百度JS接口,该接口可以辅助百度JS更好的进行定位
*
* @param webView 传入webView控件
*/
public void enableAssistanLocation(WebView webView) {
if (client != null) {
client.enableAssistantLocation(webView);
}
}
/**
* 停止H5辅助定位
*/
public void disableAssistantLocation() {
if (client != null) {
client.disableAssistantLocation();
}
}
/***
*
* @return DefaultLocationClientOption 默认O设置
*/
public LocationClientOption getDefaultLocationClientOption() {
if (mOption == null) {
mOption = new LocationClientOption();
mOption.setLocationMode(LocationMode.Hight_Accuracy); // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
mOption.setCoorType( "bd09ll" ); // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
mOption.setScanSpan(3000); // 可选,默认0,即仅定位一次,设置发起连续定位请求的间隔需要大于等于1000ms才是有效的
mOption.setIsNeedAddress(true); // 可选,设置是否需要地址信息,默认不需要
mOption.setIsNeedLocationDescribe(true); // 可选,设置是否需要地址描述
mOption.setNeedDeviceDirect(false); // 可选,设置是否需要设备方向结果
mOption.setLocationNotify(false); // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
mOption.setIgnoreKillProcess(true); // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop
mOption.setIsNeedLocationDescribe(true); // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation
mOption.setIsNeedLocationPoiList(true); // 可选,默认false,设置是否需要POI结果,可以在BDLocation
mOption.SetIgnoreCacheException(false); // 可选,默认false,设置是否收集CRASH信息,默认收集
mOption.setOpenGps(true); // 可选,默认false,设置是否开启Gps定位
mOption.setIsNeedAltitude(false); // 可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用
}
return mOption;
}
/**
* @return DIYOption 自定义Option设置
*/
public LocationClientOption getOption() {
if (DIYoption == null) {
DIYoption = new LocationClientOption();
}
return DIYoption;
}
public void start() {
synchronized (objLock) {
if (client != null && !client.isStarted()) {
client.start();
}
}
}
public void requestLocation() {
if (client != null) {
client.requestLocation();
}
}
public void stop() {
synchronized (objLock) {
if (client != null && client.isStarted()) {
client.stop();
}
}
}
public boolean isStart() {
return client.isStarted();
}
public boolean requestHotSpotState() {
return client.requestHotSpotState();
}
}
package top.littlerich.virtuallocation.service;
public class Utils {
public final static String CoorType_GCJ02 = "gcj02";
public final static String CoorType_BD09LL= "bd09ll";
public final static String CoorType_BD09MC= "bd09";
/***
*61 : GPS定位结果,GPS定位成功。
*62 : 无法获取有效定位依据,定位失败,请检查运营商网络或者wifi网络是否正常开启,尝试重新请求定位。
*63 : 网络异常,没有成功向服务器发起请求,请确认当前测试手机网络是否通畅,尝试重新请求定位。
*65 : 定位缓存的结果。
*66 : 离线定位结果。通过requestOfflineLocaiton调用时对应的返回结果。
*67 : 离线定位失败。通过requestOfflineLocaiton调用时对应的返回结果。
*68 : 网络连接失败时,查找本地离线定位时对应的返回结果。
*161: 网络定位结果,网络定位定位成功。
*162: 请求串密文解析失败。
*167: 服务端定位失败,请您检查是否禁用获取位置信息权限,尝试重新请求定位。
*502: key参数错误,请按照说明文档重新申请KEY。
*505: key不存在或者非法,请按照说明文档重新申请KEY。
*601: key服务被开发者自己禁用,请按照说明文档重新申请KEY。
*602: key mcode不匹配,您的ak配置过程中安全码设置有问题,请确保:sha1正确,“;”分号是英文状态;且包名是您当前运行应用的包名,请按照说明文档重新申请KEY。
*501~700:key验证失败,请按照说明文档重新申请KEY。
*/
public static float[] EARTH_WEIGHT = {0.1f,0.2f,0.4f,0.6f,0.8f}; // 推算计算权重_地球
//public static float[] MOON_WEIGHT = {0.0167f,0.033f,0.067f,0.1f,0.133f};
//public static float[] MARS_WEIGHT = {0.034f,0.068f,0.152f,0.228f,0.304f};
public final static int RECEIVE_TAG = 1;
public final static int DIAGNOSTIC_TAG = 2;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment