IEI服务 v2.18.01版本的 MD5 值为:9b31b0786e55bfdb6c19ae7eaf2e775b
以下内容为反编译后的 BaiduMapUtils.java 源代码,内容仅作参考
package io.inory.uniplugin;
import android.content.Context;
import android.util.Log;
import androidx.vectordrawable.graphics.drawable.PathInterpolatorCompat;
import com.alibaba.fastjson.JSONObject;
import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
public class BaiduMapUtils {
private static Context bdContext;
private static BaiduMapUtils instance;
private LocationClient locClientOne;
private LocationCallBack locationCallBack;
String TAG = "BaiduMapUtils";
private BDAbstractLocationListener mListener = new BDAbstractLocationListener() {
@Override
public void onReceiveLocation(BDLocation bDLocation) {
if (bDLocation == null) {
BaiduMapUtils.this.locationCallBack.onError(HKLocationRes.getsInstance(0, "定位失败,未返回任何信息"));
return;
}
HKLocationRes hKLocationRes = HKLocationRes.getsInstance(bDLocation);
if (bDLocation.getLocType() == 167) {
hKLocationRes.setMsg("服务端网络定位失败,可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com,会有人追查原因");
BaiduMapUtils.this.locationCallBack.onError(hKLocationRes);
return;
}
if (bDLocation.getLocType() == 63) {
hKLocationRes.setMsg("网络不通导致定位失败,请检查网络是否通畅");
BaiduMapUtils.this.locationCallBack.onError(hKLocationRes);
} else if (bDLocation.getLocType() == 62) {
hKLocationRes.setMsg("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
BaiduMapUtils.this.locationCallBack.onError(hKLocationRes);
} else if (bDLocation.getLocType() == 61 || bDLocation.getLocType() == 161 || bDLocation.getLocType() == 66) {
BaiduMapUtils.this.locationCallBack.onSuccess(bDLocation);
} else {
BaiduMapUtils.this.locationCallBack.onError(hKLocationRes);
}
}
@Override
public void onConnectHotSpotMessage(String str, int i) {
super.onConnectHotSpotMessage(str, i);
}
@Override
public void onLocDiagnosticMessage(int i, int i2, String str) {
super.onLocDiagnosticMessage(i, i2, str);
StringBuffer stringBuffer = new StringBuffer(256);
if (i == 161) {
if (i2 == 1) {
stringBuffer.append("网络定位成功,没有开启GPS,建议打开GPS会更好");
stringBuffer.append("\n" + str);
return;
}
if (i2 == 2) {
stringBuffer.append("网络定位成功,没有开启Wi-Fi,建议打开Wi-Fi会更好");
stringBuffer.append("\n" + str);
return;
}
return;
}
if (i == 67) {
if (i2 == 3) {
stringBuffer.append("定位失败,请您检查您的网络状态");
stringBuffer.append("\n" + str);
BaiduMapUtils.this.locationCallBack.onError(HKLocationRes.getsInstance(i, stringBuffer.toString()));
return;
}
return;
}
if (i != 62) {
if (i == 167 && i2 == 8) {
stringBuffer.append("定位失败,请确认您定位的开关打开状态,是否赋予APP定位权限");
stringBuffer.append("\n" + str);
BaiduMapUtils.this.locationCallBack.onError(HKLocationRes.getsInstance(i, stringBuffer.toString()));
return;
}
return;
}
if (i2 == 4) {
stringBuffer.append("定位失败,无法获取任何有效定位依据");
stringBuffer.append("\n" + str);
BaiduMapUtils.this.locationCallBack.onError(HKLocationRes.getsInstance(i, stringBuffer.toString()));
return;
}
if (i2 == 5) {
stringBuffer.append("定位失败,无法获取有效定位依据,请检查运营商网络或者Wi-Fi网络是否正常开启,尝试重新请求定位");
stringBuffer.append(str);
BaiduMapUtils.this.locationCallBack.onError(HKLocationRes.getsInstance(i, stringBuffer.toString()));
return;
}
if (i2 == 6) {
stringBuffer.append("定位失败,无法获取有效定位依据,请尝试插入一张sim卡或打开Wi-Fi重试");
stringBuffer.append("\n" + str);
BaiduMapUtils.this.locationCallBack.onError(HKLocationRes.getsInstance(i, stringBuffer.toString()));
return;
}
if (i2 == 7) {
stringBuffer.append("定位失败,飞行模式下无法获取有效定位依据,请关闭飞行模式重试");
stringBuffer.append("\n" + str);
BaiduMapUtils.this.locationCallBack.onError(HKLocationRes.getsInstance(i, stringBuffer.toString()));
return;
}
if (i2 == 9) {
stringBuffer.append("定位失败,无法获取任何有效定位依据");
stringBuffer.append("\n" + str);
BaiduMapUtils.this.locationCallBack.onError(HKLocationRes.getsInstance(i, stringBuffer.toString()));
}
}
};
public interface ContinuousSiteCallBack {
void onContinuousSite(BDLocation bDLocation);
}
public interface LocationCallBack {
void onError(HKLocationRes hKLocationRes);
void onSuccess(BDLocation bDLocation);
}
private BaiduMapUtils(Context context) {
bdContext = context.getApplicationContext();
}
public static BaiduMapUtils getsInstance(Context context) {
BaiduMapUtils baiduMapUtils;
synchronized (BaiduMapUtils.class) {
if (instance == null) {
instance = new BaiduMapUtils(context);
}
baiduMapUtils = instance;
}
return baiduMapUtils;
}
public void stop() {
LocationClient locationClient = this.locClientOne;
if (locationClient != null) {
locationClient.unRegisterLocationListener(this.mListener);
this.locClientOne.stop();
this.locClientOne = null;
}
}
public void initOnceSite(JSONObject jSONObject, LocationCallBack locationCallBack) {
HKLocOptions hKLocOptions;
try {
this.locationCallBack = locationCallBack;
LocationClient.setAgreePrivacy(true);
LocationClient locationClient = new LocationClient(bdContext);
this.locClientOne = locationClient;
locationClient.registerLocationListener(this.mListener);
LocationClientOption defaultLocationClientOption = getDefaultLocationClientOption();
defaultLocationClientOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
defaultLocationClientOption.setIsNeedAddress(true);
defaultLocationClientOption.setNeedNewVersionRgc(true);
if (jSONObject != null && (hKLocOptions = (HKLocOptions) JSONObject.parseObject(jSONObject.toJSONString(), HKLocOptions.class)) != null) {
if (hKLocOptions.getOnceLocation() != null) {
defaultLocationClientOption.setOnceLocation(hKLocOptions.getOnceLocation().booleanValue());
}
defaultLocationClientOption.setCoorType("gcj02");
if (hKLocOptions.getCoorType() != null) {
defaultLocationClientOption.setCoorType(hKLocOptions.getCoorType());
}
defaultLocationClientOption.setScanSpan(hKLocOptions.getScanSpan());
if (hKLocOptions.getNeedAddress() != null) {
defaultLocationClientOption.setIsNeedAddress(hKLocOptions.getNeedAddress().booleanValue());
}
if (hKLocOptions.getNeedAltitude() != null) {
defaultLocationClientOption.setIsNeedAltitude(hKLocOptions.getNeedAltitude().booleanValue());
}
if (hKLocOptions.getNeedLocationDescribe() != null) {
defaultLocationClientOption.setIsNeedLocationDescribe(hKLocOptions.getNeedLocationDescribe().booleanValue());
}
if (hKLocOptions.getLocationNotify() != null) {
defaultLocationClientOption.setLocationNotify(hKLocOptions.getLocationNotify().booleanValue());
}
if (hKLocOptions.getIgnoreKillProcess() != null) {
defaultLocationClientOption.setIgnoreKillProcess(hKLocOptions.getIgnoreKillProcess().booleanValue());
}
if (hKLocOptions.getNeedLocationPoiLis() != null) {
defaultLocationClientOption.setIsNeedLocationPoiList(hKLocOptions.getNeedLocationPoiLis().booleanValue());
}
if (hKLocOptions.getIgnoreCacheException() != null) {
defaultLocationClientOption.SetIgnoreCacheException(hKLocOptions.getIgnoreCacheException().booleanValue());
}
if (hKLocOptions.getWifiCacheTimeOut() > 0) {
defaultLocationClientOption.setWifiCacheTimeOut(hKLocOptions.getWifiCacheTimeOut());
}
if (hKLocOptions.getLocationMode() == 0) {
defaultLocationClientOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
} else if (hKLocOptions.getLocationMode() == 1) {
defaultLocationClientOption.setLocationMode(LocationClientOption.LocationMode.Battery_Saving);
} else if (hKLocOptions.getLocationMode() == 2) {
defaultLocationClientOption.setLocationMode(LocationClientOption.LocationMode.Device_Sensors);
} else if (hKLocOptions.getLocationMode() == 4) {
defaultLocationClientOption.setLocationMode(LocationClientOption.LocationMode.Fuzzy_Locating);
}
if (hKLocOptions.getFirstLocType() == 0) {
defaultLocationClientOption.setFirstLocType(LocationClientOption.FirstLocType.SPEED_IN_FIRST_LOC);
} else if (hKLocOptions.getFirstLocType() == 1) {
defaultLocationClientOption.setFirstLocType(LocationClientOption.FirstLocType.ACCURACY_IN_FIRST_LOC);
}
if (hKLocOptions.getLocationPurpose() == 0) {
defaultLocationClientOption.setLocationPurpose(LocationClientOption.BDLocationPurpose.SignIn);
} else if (hKLocOptions.getLocationPurpose() == 1) {
defaultLocationClientOption.setLocationPurpose(LocationClientOption.BDLocationPurpose.Sport);
} else if (hKLocOptions.getLocationPurpose() == 2) {
defaultLocationClientOption.setLocationPurpose(LocationClientOption.BDLocationPurpose.Transport);
}
}
this.locClientOne.setLocOption(defaultLocationClientOption);
this.locClientOne.start();
} catch (Exception e) {
e.printStackTrace();
}
}
public void initContinuousSite(final ContinuousSiteCallBack continuousSiteCallBack) {
try {
LocationClient.setAgreePrivacy(true);
final LocationClient locationClient = new LocationClient(bdContext);
locationClient.registerLocationListener(new BDAbstractLocationListener() {
@Override
public void onReceiveLocation(BDLocation bDLocation) {
String addrStr = bDLocation.getAddrStr();
Log.e("查看位置获取到的信息", "连续地址:" + addrStr);
if (addrStr != null) {
continuousSiteCallBack.onContinuousSite(bDLocation);
} else {
locationClient.stop();
BaiduMapUtils.this.initContinuousSite(continuousSiteCallBack);
}
}
});
LocationClientOption locationClientOption = new LocationClientOption();
locationClientOption.setScanSpan(10000);
locationClientOption.setIsNeedAddress(true);
locationClientOption.setIsNeedLocationDescribe(true);
locationClient.setLocOption(locationClientOption);
locationClient.start();
} catch (Exception e) {
e.printStackTrace();
}
}
public LocationClientOption getDefaultLocationClientOption() {
LocationClientOption locationClientOption = new LocationClientOption();
locationClientOption.setCoorType("gcj02");
locationClientOption.setScanSpan(PathInterpolatorCompat.MAX_NUM_POINTS);
locationClientOption.setIsNeedAddress(true);
locationClientOption.setIsNeedLocationDescribe(true);
locationClientOption.setNeedDeviceDirect(false);
locationClientOption.setLocationNotify(false);
locationClientOption.setIgnoreKillProcess(true);
locationClientOption.setIsNeedLocationDescribe(true);
locationClientOption.setIsNeedLocationPoiList(true);
locationClientOption.SetIgnoreCacheException(false);
locationClientOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
locationClientOption.setIsNeedAltitude(false);
locationClientOption.setFirstLocType(LocationClientOption.FirstLocType.SPEED_IN_FIRST_LOC);
return locationClientOption;
}
}