|
@@ -28,10 +28,14 @@ import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
-import com.amap.api.location.AMapLocation;
|
|
|
|
-import com.amap.api.location.AMapLocationClient;
|
|
|
|
-import com.amap.api.location.AMapLocationClientOption;
|
|
|
|
-import com.amap.api.location.AMapLocationListener;
|
|
|
|
|
|
+//import com.amap.api.location.AMapLocation;
|
|
|
|
+//import com.amap.api.location.AMapLocationClient;
|
|
|
|
+//import com.amap.api.location.AMapLocationClientOption;
|
|
|
|
+//import com.amap.api.location.AMapLocationListener;
|
|
|
|
+import com.baidu.location.BDAbstractLocationListener;
|
|
|
|
+import com.baidu.location.BDLocation;
|
|
|
|
+import com.baidu.location.LocationClient;
|
|
|
|
+import com.baidu.location.LocationClientOption;
|
|
import com.example.moduleGis.gnsstest.DiffConnectManager;
|
|
import com.example.moduleGis.gnsstest.DiffConnectManager;
|
|
import com.example.moduleGis.gnsstest.GnssListener;
|
|
import com.example.moduleGis.gnsstest.GnssListener;
|
|
import com.example.moduleGis.gnsstest.GnssServiceManager;
|
|
import com.example.moduleGis.gnsstest.GnssServiceManager;
|
|
@@ -1280,358 +1284,359 @@ public class APIModuleGis extends UZModule {
|
|
/**
|
|
/**
|
|
* TODO 高德地图服务相关
|
|
* TODO 高德地图服务相关
|
|
*/
|
|
*/
|
|
- //实时定位状态码
|
|
|
|
- public volatile static Integer amapLocationErrorCode = 0;
|
|
|
|
- //定位堆栈, 长度不可超过10 , 超过10 则把第一个顶掉,以此类推
|
|
|
|
- public volatile static List<AMapLocation> aMapLocations = new ArrayList<>();
|
|
|
|
- // 向aMapLocations集合中添加对象的方法
|
|
|
|
- public static synchronized void addLocation(AMapLocation location) {
|
|
|
|
- if (aMapLocations.size() >= 10) {
|
|
|
|
- // 如果长度超过10,移除第一个(即索引为0的元素)
|
|
|
|
- aMapLocations.remove(0);
|
|
|
|
- }
|
|
|
|
- // 添加新的元素
|
|
|
|
- aMapLocations.add(location);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //声明AMapLocationClient类对象
|
|
|
|
- public AMapLocationClient mLocationClient = null;
|
|
|
|
- //声明AMapLocationClientOption对象
|
|
|
|
- public AMapLocationClientOption mLocationOption = null;
|
|
|
|
- //声明定位回调监听器
|
|
|
|
- public AMapLocationListener mLocationListener = new AMapLocationListener() {
|
|
|
|
- @Override
|
|
|
|
- public void onLocationChanged(AMapLocation aMapLocation) {
|
|
|
|
- if (aMapLocation != null) {
|
|
|
|
- int locationSize = 0;
|
|
|
|
- Log.i("参数时间3",""+(System.currentTimeMillis()));
|
|
|
|
- AMapZidingyiLocation result = null;
|
|
|
|
- if (aMapLocation.getErrorCode() == 0) {
|
|
|
|
- result = new AMapZidingyiLocation(0, System.currentTimeMillis(), aMapLocation);
|
|
|
|
- }else{
|
|
|
|
- result = new AMapZidingyiLocation(aMapLocation.getErrorCode(), System.currentTimeMillis(), null);
|
|
|
|
- }
|
|
|
|
- synchronized (LATCH_COMM){
|
|
|
|
- lastAMapLocations.add(result);
|
|
|
|
- locationSize = lastAMapLocations.size();
|
|
|
|
- }
|
|
|
|
- if (mWaitAMapSingleBack.compareAndSet(true, false)){
|
|
|
|
- if (mLocationClient != null && locationSize >= 10){
|
|
|
|
- mLocationClient.stopLocation();
|
|
|
|
- mStartedAMapLocation.set(false);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- //TODO Lx 初始化定位对象
|
|
|
|
- public ModuleResult jsmethod_initGdMap_sync(UZModuleContext moduleContext){
|
|
|
|
- JSONObject res = new JSONObject();
|
|
|
|
- String code = "1";
|
|
|
|
- String msg = "error";
|
|
|
|
- try{
|
|
|
|
- //TODO 合规检查
|
|
|
|
- AMapLocationClient.updatePrivacyShow(moduleContext.getContext(),true,true);
|
|
|
|
- AMapLocationClient.updatePrivacyAgree(moduleContext.getContext(),true);
|
|
|
|
- //TODO 启动服务相关判断
|
|
|
|
- res.put("code",code);
|
|
|
|
- res.put("msg",msg);
|
|
|
|
- if(mLocationClient != null) {
|
|
|
|
- mLocationClient.stopLocation();
|
|
|
|
- mLocationClient.onDestroy();
|
|
|
|
- mInitedAMapSdk.set(false);
|
|
|
|
- mStartedAMapLocation.set(false);
|
|
|
|
- mWaitAMapSingleBack.set(false);
|
|
|
|
- }
|
|
|
|
- //初始化定位
|
|
|
|
- mLocationClient = new AMapLocationClient(moduleContext.getContext());
|
|
|
|
- //设置定位回调监听
|
|
|
|
- mLocationClient.setLocationListener(mLocationListener);
|
|
|
|
- code = "0";
|
|
|
|
- msg = "success";
|
|
|
|
- res.put("code",code);
|
|
|
|
- res.put("msg",msg);
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }catch(Exception ex){
|
|
|
|
- code = "1";
|
|
|
|
- msg = ex.getLocalizedMessage();
|
|
|
|
- try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
- Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //TODO 高效率启动高德定位
|
|
|
|
- private final byte[] LATCH_COMM = new byte[0];
|
|
|
|
- AtomicBoolean mInitedAMapSdk = new AtomicBoolean(false);
|
|
|
|
- AtomicBoolean mStartedAMapLocation = new AtomicBoolean(false);
|
|
|
|
- AtomicBoolean mWaitAMapSingleBack = new AtomicBoolean(false);
|
|
|
|
- class AMapZidingyiLocation{
|
|
|
|
- int code = 1; //0--成功;非0--失败
|
|
|
|
- long acceptTime = 0L; //接收高德定位回调的时间
|
|
|
|
- Map<String,Object> data = null; //高德定位结果
|
|
|
|
-
|
|
|
|
- public AMapZidingyiLocation(){
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- public AMapZidingyiLocation(int code,long acceptTime,AMapLocation data){
|
|
|
|
- this.code = code;
|
|
|
|
- this.acceptTime = acceptTime;
|
|
|
|
- Map<String,Object> newData = new HashMap<>();
|
|
|
|
- if(data!=null) {
|
|
|
|
- newData.put("latitude", data.getLatitude());//纬度
|
|
|
|
- newData.put("longitude", data.getLongitude());//经度
|
|
|
|
- newData.put("accurac", data.getAccuracy());//精度
|
|
|
|
- newData.put("altitude", data.getAltitude());//海拔
|
|
|
|
- newData.put("speed", data.getSpeed());//速度
|
|
|
|
- newData.put("bearing", data.getBearing());//方向角
|
|
|
|
- newData.put("buildingId", data.getBuildingId());//室内定位建筑物Id
|
|
|
|
- newData.put("floor", data.getFloor());//室内定位楼层
|
|
|
|
- newData.put("address", data.getAddress());//地址描述
|
|
|
|
- newData.put("country", data.getCountry());//国家
|
|
|
|
- newData.put("province", data.getProvince());//省份
|
|
|
|
- newData.put("city", data.getCity());//城市
|
|
|
|
- newData.put("district", data.getDistrict());//城区
|
|
|
|
- newData.put("street", data.getStreet());//街道
|
|
|
|
- newData.put("streetNum", data.getStreetNum());//街道门牌号
|
|
|
|
- newData.put("cityCod", data.getCityCode());//城市编码
|
|
|
|
- newData.put("adCode", data.getAdCode());//区域编码
|
|
|
|
- newData.put("poiName", data.getPoiName());//当前位置POI名称
|
|
|
|
- newData.put("aoiName", data.getAoiName());//当前位置所处AOI名称
|
|
|
|
- newData.put("gpsAccuracyStatus", data.getGpsAccuracyStatus());//设备当前 GPS 状态
|
|
|
|
- newData.put("locationType", data.getLocationType());//定位来源
|
|
|
|
- newData.put("locationDetail", data.getLocationDetail());//定位信息描述
|
|
|
|
- newData.put("errorInfo", data.getErrorInfo());//定位错误信息描述
|
|
|
|
- newData.put("errorCode", data.getErrorCode());//定位错误码
|
|
|
|
- }
|
|
|
|
- this.data = newData;
|
|
|
|
- }
|
|
|
|
- public String toString(){
|
|
|
|
- return "{\"code\":"+code+",\"acceptTime\":"+acceptTime+",\"data\":"+ (data==null?"{}": com.alibaba.fastjson.JSONObject.toJSONString(data)) +"}";
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- CircularFifoQueue<AMapZidingyiLocation> lastAMapLocations = new CircularFifoQueue<>(10);
|
|
|
|
-
|
|
|
|
- public ModuleResult jsmethod_startAmapLocation_sync(UZModuleContext moduleContext){
|
|
|
|
- JSONObject res = new JSONObject();
|
|
|
|
- String code = "1";
|
|
|
|
- String msg = "error";
|
|
|
|
- Boolean onceFlag = moduleContext.optBoolean("onceFlag");
|
|
|
|
- try{
|
|
|
|
- //TODO 启动服务相关判断
|
|
|
|
- long callTm = System.currentTimeMillis();
|
|
|
|
- if (mInitedAMapSdk.compareAndSet(false, true)){
|
|
|
|
- //初始化SDK参数:1) 设置连续定位; 2) 关闭缓存策略; 3) 设置连续定位间隔为1000ms; 4) 其他参数均不填使用其默认配置
|
|
|
|
- sendAMapGis();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ((onceFlag == null) || onceFlag || mStartedAMapLocation.compareAndSet(false, true)){
|
|
|
|
- synchronized (LATCH_COMM){
|
|
|
|
- lastAMapLocations.clear();
|
|
|
|
- }
|
|
|
|
- //调用高德SDK开始定位函数
|
|
|
|
- if(mLocationClient != null)
|
|
|
|
- startAMapGis(onceFlag==null?true:onceFlag);
|
|
|
|
- mWaitAMapSingleBack.set(onceFlag==null?true:onceFlag);
|
|
|
|
- }
|
|
|
|
- long ff = System.currentTimeMillis();
|
|
|
|
- //Log.i("结束参数设置时间:",""+System.currentTimeMillis());
|
|
|
|
-
|
|
|
|
- /*do{
|
|
|
|
- long lastAcceptTm = 0L;
|
|
|
|
- synchronized (LATCH_COMM){
|
|
|
|
- if (lastAMapLocations.size() > 0)
|
|
|
|
- lastAcceptTm = lastAMapLocations.get(lastAMapLocations.size()-1).acceptTime;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Log.i("参数时间1",(System.currentTimeMillis()-ff)+" "+lastAcceptTm);
|
|
|
|
-
|
|
|
|
- if (lastAcceptTm >= callTm){
|
|
|
|
- break;
|
|
|
|
- }else{
|
|
|
|
-// Log.i("开始睡眠时间:",""+System.currentTimeMillis());
|
|
|
|
- try{
|
|
|
|
- Thread.sleep(200);
|
|
|
|
- }catch (Exception e){
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
-// Log.i("结束睡眠时间:",""+System.currentTimeMillis());
|
|
|
|
- }
|
|
|
|
- }while(mStartedAMapLocation.get() && (System.currentTimeMillis() - callTm) <= 20000);*/
|
|
|
|
-
|
|
|
|
- Log.i("参数时间2:",""+(System.currentTimeMillis()-ff));
|
|
|
|
- List<String> result = new ArrayList<>();
|
|
|
|
- synchronized (LATCH_COMM){
|
|
|
|
- for (AMapZidingyiLocation element : lastAMapLocations){
|
|
|
|
- result.add(0, element==null?"{}":element.toString());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- code = "0";
|
|
|
|
- msg = "success";
|
|
|
|
- res.put("code",code);
|
|
|
|
- res.put("msg",msg);
|
|
|
|
- res.put("data", result);
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }catch(Exception ex){
|
|
|
|
- code = "1";
|
|
|
|
- msg = ex.getLocalizedMessage();
|
|
|
|
- try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
- Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- public ModuleResult jsmethod_stopAmapLocation_sync(UZModuleContext moduleContext){
|
|
|
|
- JSONObject res = new JSONObject();
|
|
|
|
- String code = "1";
|
|
|
|
- String msg = "error";
|
|
|
|
- try{
|
|
|
|
- stopAMapGis();
|
|
|
|
- code = "0";
|
|
|
|
- msg = "success";
|
|
|
|
- res.put("code",code);
|
|
|
|
- res.put("msg",msg);
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }catch(Exception ex){
|
|
|
|
- code = "1";
|
|
|
|
- msg = ex.getLocalizedMessage();
|
|
|
|
- try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
- Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- public ModuleResult jsmethod_getLocationList_sync(UZModuleContext moduleContext){
|
|
|
|
- JSONObject res = new JSONObject();
|
|
|
|
- String code = "1";
|
|
|
|
- String msg = "error";
|
|
|
|
- try{
|
|
|
|
- code = "0";
|
|
|
|
- msg = "success";
|
|
|
|
- res.put("code",code);
|
|
|
|
- res.put("msg",msg);
|
|
|
|
- List<String> result = new ArrayList<>();
|
|
|
|
- synchronized (LATCH_COMM){
|
|
|
|
- for (AMapZidingyiLocation element : lastAMapLocations){
|
|
|
|
- result.add(0, element.toString()/*com.qx.wz.external.fastjson.JSONObject.toJSONString(element)*/);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- res.put("data",result);
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }catch(Exception ex){
|
|
|
|
- code = "1";
|
|
|
|
- msg = ex.getLocalizedMessage();
|
|
|
|
- try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
- Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public ModuleResult sendAMapGis(){
|
|
|
|
- JSONObject res = new JSONObject();
|
|
|
|
- String code = "1";
|
|
|
|
- String msg = "error";
|
|
|
|
- try{
|
|
|
|
- //TODO 启动服务相关判断
|
|
|
|
- res.put("code",code);
|
|
|
|
- res.put("msg",msg);
|
|
|
|
- //初始化AMapLocationClientOption对象
|
|
|
|
- mLocationOption = new AMapLocationClientOption();
|
|
|
|
- AMapLocationClientOption option = new AMapLocationClientOption();
|
|
|
|
- /**
|
|
|
|
- * 设置定位场景,目前支持三种场景(签到、出行、运动,默认无场景)
|
|
|
|
- */
|
|
|
|
- option.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.SignIn);
|
|
|
|
- if(null != mLocationClient){
|
|
|
|
- mLocationClient.setLocationOption(option);
|
|
|
|
- //设置场景模式后最好调用一次stop,再调用start以保证场景模式生效
|
|
|
|
|
|
+// //实时定位状态码
|
|
|
|
+// public volatile static Integer amapLocationErrorCode = 0;
|
|
|
|
+// //定位堆栈, 长度不可超过10 , 超过10 则把第一个顶掉,以此类推
|
|
|
|
+// public volatile static List<AMapLocation> aMapLocations = new ArrayList<>();
|
|
|
|
+// // 向aMapLocations集合中添加对象的方法
|
|
|
|
+// public static synchronized void addLocation(AMapLocation location) {
|
|
|
|
+// if (aMapLocations.size() >= 10) {
|
|
|
|
+// // 如果长度超过10,移除第一个(即索引为0的元素)
|
|
|
|
+// aMapLocations.remove(0);
|
|
|
|
+// }
|
|
|
|
+// // 添加新的元素
|
|
|
|
+// aMapLocations.add(location);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// //声明AMapLocationClient类对象
|
|
|
|
+// public AMapLocationClient mLocationClient = null;
|
|
|
|
+// //声明AMapLocationClientOption对象
|
|
|
|
+// public AMapLocationClientOption mLocationOption = null;
|
|
|
|
+// //声明定位回调监听器
|
|
|
|
+// public AMapLocationListener mLocationListener = new AMapLocationListener() {
|
|
|
|
+// @Override
|
|
|
|
+// public void onLocationChanged(AMapLocation aMapLocation) {
|
|
|
|
+// if (aMapLocation != null) {
|
|
|
|
+// int locationSize = 0;
|
|
|
|
+// Log.i("参数时间3",""+(System.currentTimeMillis()));
|
|
|
|
+// AMapZidingyiLocation result = null;
|
|
|
|
+// if (aMapLocation.getErrorCode() == 0) {
|
|
|
|
+// result = new AMapZidingyiLocation(0, System.currentTimeMillis(), aMapLocation);
|
|
|
|
+// }else{
|
|
|
|
+// result = new AMapZidingyiLocation(aMapLocation.getErrorCode(), System.currentTimeMillis(), null);
|
|
|
|
+// }
|
|
|
|
+// synchronized (LATCH_COMM){
|
|
|
|
+// lastAMapLocations.add(result);
|
|
|
|
+// locationSize = lastAMapLocations.size();
|
|
|
|
+// }
|
|
|
|
+// if (mWaitAMapSingleBack.compareAndSet(true, false)){
|
|
|
|
+// if (mLocationClient != null && locationSize >= 10){
|
|
|
|
+// mLocationClient.stopLocation();
|
|
|
|
+// mStartedAMapLocation.set(false);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// };
|
|
|
|
+// //TODO Lx 初始化定位对象
|
|
|
|
+// public ModuleResult jsmethod_initGdMap_sync(UZModuleContext moduleContext){
|
|
|
|
+// JSONObject res = new JSONObject();
|
|
|
|
+// String code = "1";
|
|
|
|
+// String msg = "error";
|
|
|
|
+// try{
|
|
|
|
+// //TODO 合规检查
|
|
|
|
+// AMapLocationClient.updatePrivacyShow(moduleContext.getContext(),true,true);
|
|
|
|
+// AMapLocationClient.updatePrivacyAgree(moduleContext.getContext(),true);
|
|
|
|
+// //TODO 启动服务相关判断
|
|
|
|
+// res.put("code",code);
|
|
|
|
+// res.put("msg",msg);
|
|
|
|
+// if(mLocationClient != null) {
|
|
|
|
+// mLocationClient.stopLocation();
|
|
|
|
+// mLocationClient.onDestroy();
|
|
|
|
+// mInitedAMapSdk.set(false);
|
|
|
|
+// mStartedAMapLocation.set(false);
|
|
|
|
+// mWaitAMapSingleBack.set(false);
|
|
|
|
+// }
|
|
|
|
+// //初始化定位
|
|
|
|
+// mLocationClient = new AMapLocationClient(moduleContext.getContext());
|
|
|
|
+// //设置定位回调监听
|
|
|
|
+// mLocationClient.setLocationListener(mLocationListener);
|
|
|
|
+// code = "0";
|
|
|
|
+// msg = "success";
|
|
|
|
+// res.put("code",code);
|
|
|
|
+// res.put("msg",msg);
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }catch(Exception ex){
|
|
|
|
+// code = "1";
|
|
|
|
+// msg = ex.getLocalizedMessage();
|
|
|
|
+// try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
+// Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// //TODO 高效率启动高德定位
|
|
|
|
+// private final byte[] LATCH_COMM = new byte[0];
|
|
|
|
+// AtomicBoolean mInitedAMapSdk = new AtomicBoolean(false);
|
|
|
|
+// AtomicBoolean mStartedAMapLocation = new AtomicBoolean(false);
|
|
|
|
+// AtomicBoolean mWaitAMapSingleBack = new AtomicBoolean(false);
|
|
|
|
+// class AMapZidingyiLocation{
|
|
|
|
+// int code = 1; //0--成功;非0--失败
|
|
|
|
+// long acceptTime = 0L; //接收高德定位回调的时间
|
|
|
|
+// Map<String,Object> data = null; //高德定位结果
|
|
|
|
+//
|
|
|
|
+// public AMapZidingyiLocation(){
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// public AMapZidingyiLocation(int code,long acceptTime,AMapLocation data){
|
|
|
|
+// this.code = code;
|
|
|
|
+// this.acceptTime = acceptTime;
|
|
|
|
+// Map<String,Object> newData = new HashMap<>();
|
|
|
|
+// if(data!=null) {
|
|
|
|
+// newData.put("latitude", data.getLatitude());//纬度
|
|
|
|
+// newData.put("longitude", data.getLongitude());//经度
|
|
|
|
+// newData.put("accurac", data.getAccuracy());//精度
|
|
|
|
+// newData.put("altitude", data.getAltitude());//海拔
|
|
|
|
+// newData.put("speed", data.getSpeed());//速度
|
|
|
|
+// newData.put("bearing", data.getBearing());//方向角
|
|
|
|
+// newData.put("buildingId", data.getBuildingId());//室内定位建筑物Id
|
|
|
|
+// newData.put("floor", data.getFloor());//室内定位楼层
|
|
|
|
+// newData.put("address", data.getAddress());//地址描述
|
|
|
|
+// newData.put("country", data.getCountry());//国家
|
|
|
|
+// newData.put("province", data.getProvince());//省份
|
|
|
|
+// newData.put("city", data.getCity());//城市
|
|
|
|
+// newData.put("district", data.getDistrict());//城区
|
|
|
|
+// newData.put("street", data.getStreet());//街道
|
|
|
|
+// newData.put("streetNum", data.getStreetNum());//街道门牌号
|
|
|
|
+// newData.put("cityCod", data.getCityCode());//城市编码
|
|
|
|
+// newData.put("adCode", data.getAdCode());//区域编码
|
|
|
|
+// newData.put("poiName", data.getPoiName());//当前位置POI名称
|
|
|
|
+// newData.put("aoiName", data.getAoiName());//当前位置所处AOI名称
|
|
|
|
+// newData.put("gpsAccuracyStatus", data.getGpsAccuracyStatus());//设备当前 GPS 状态
|
|
|
|
+// newData.put("locationType", data.getLocationType());//定位来源
|
|
|
|
+// newData.put("locationDetail", data.getLocationDetail());//定位信息描述
|
|
|
|
+// newData.put("errorInfo", data.getErrorInfo());//定位错误信息描述
|
|
|
|
+// newData.put("errorCode", data.getErrorCode());//定位错误码
|
|
|
|
+// }
|
|
|
|
+// this.data = newData;
|
|
|
|
+// }
|
|
|
|
+// public String toString(){
|
|
|
|
+// return "{\"code\":"+code+",\"acceptTime\":"+acceptTime+",\"data\":"+ (data==null?"{}": com.alibaba.fastjson.JSONObject.toJSONString(data)) +"}";
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// CircularFifoQueue<AMapZidingyiLocation> lastAMapLocations = new CircularFifoQueue<>(10);
|
|
|
|
+//
|
|
|
|
+// public ModuleResult jsmethod_startAmapLocation_sync(UZModuleContext moduleContext){
|
|
|
|
+// JSONObject res = new JSONObject();
|
|
|
|
+// String code = "1";
|
|
|
|
+// String msg = "error";
|
|
|
|
+// Boolean onceFlag = moduleContext.optBoolean("onceFlag");
|
|
|
|
+// try{
|
|
|
|
+// //TODO 启动服务相关判断
|
|
|
|
+// long callTm = System.currentTimeMillis();
|
|
|
|
+// if (mInitedAMapSdk.compareAndSet(false, true)){
|
|
|
|
+// //初始化SDK参数:1) 设置连续定位; 2) 关闭缓存策略; 3) 设置连续定位间隔为1000ms; 4) 其他参数均不填使用其默认配置
|
|
|
|
+// sendAMapGis();
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// if ((onceFlag == null) || onceFlag || mStartedAMapLocation.compareAndSet(false, true)){
|
|
|
|
+// synchronized (LATCH_COMM){
|
|
|
|
+// lastAMapLocations.clear();
|
|
|
|
+// }
|
|
|
|
+// //调用高德SDK开始定位函数
|
|
|
|
+// if(mLocationClient != null)
|
|
|
|
+// startAMapGis(onceFlag==null?true:onceFlag);
|
|
|
|
+// mWaitAMapSingleBack.set(onceFlag==null?true:onceFlag);
|
|
|
|
+// }
|
|
|
|
+// long ff = System.currentTimeMillis();
|
|
|
|
+// //Log.i("结束参数设置时间:",""+System.currentTimeMillis());
|
|
|
|
+//
|
|
|
|
+// /*do{
|
|
|
|
+// long lastAcceptTm = 0L;
|
|
|
|
+// synchronized (LATCH_COMM){
|
|
|
|
+// if (lastAMapLocations.size() > 0)
|
|
|
|
+// lastAcceptTm = lastAMapLocations.get(lastAMapLocations.size()-1).acceptTime;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// Log.i("参数时间1",(System.currentTimeMillis()-ff)+" "+lastAcceptTm);
|
|
|
|
+//
|
|
|
|
+// if (lastAcceptTm >= callTm){
|
|
|
|
+// break;
|
|
|
|
+// }else{
|
|
|
|
+//// Log.i("开始睡眠时间:",""+System.currentTimeMillis());
|
|
|
|
+// try{
|
|
|
|
+// Thread.sleep(200);
|
|
|
|
+// }catch (Exception e){
|
|
|
|
+// e.printStackTrace();
|
|
|
|
+// }
|
|
|
|
+//// Log.i("结束睡眠时间:",""+System.currentTimeMillis());
|
|
|
|
+// }
|
|
|
|
+// }while(mStartedAMapLocation.get() && (System.currentTimeMillis() - callTm) <= 20000);*/
|
|
|
|
+//
|
|
|
|
+// Log.i("参数时间2:",""+(System.currentTimeMillis()-ff));
|
|
|
|
+// List<String> result = new ArrayList<>();
|
|
|
|
+// synchronized (LATCH_COMM){
|
|
|
|
+// for (AMapZidingyiLocation element : lastAMapLocations){
|
|
|
|
+// result.add(0, element==null?"{}":element.toString());
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// code = "0";
|
|
|
|
+// msg = "success";
|
|
|
|
+// res.put("code",code);
|
|
|
|
+// res.put("msg",msg);
|
|
|
|
+// res.put("data", result);
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }catch(Exception ex){
|
|
|
|
+// code = "1";
|
|
|
|
+// msg = ex.getLocalizedMessage();
|
|
|
|
+// try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
+// Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// public ModuleResult jsmethod_stopAmapLocation_sync(UZModuleContext moduleContext){
|
|
|
|
+// JSONObject res = new JSONObject();
|
|
|
|
+// String code = "1";
|
|
|
|
+// String msg = "error";
|
|
|
|
+// try{
|
|
|
|
+// stopAMapGis();
|
|
|
|
+// code = "0";
|
|
|
|
+// msg = "success";
|
|
|
|
+// res.put("code",code);
|
|
|
|
+// res.put("msg",msg);
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }catch(Exception ex){
|
|
|
|
+// code = "1";
|
|
|
|
+// msg = ex.getLocalizedMessage();
|
|
|
|
+// try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
+// Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// public ModuleResult jsmethod_getLocationList_sync(UZModuleContext moduleContext){
|
|
|
|
+// JSONObject res = new JSONObject();
|
|
|
|
+// String code = "1";
|
|
|
|
+// String msg = "error";
|
|
|
|
+// try{
|
|
|
|
+// code = "0";
|
|
|
|
+// msg = "success";
|
|
|
|
+// res.put("code",code);
|
|
|
|
+// res.put("msg",msg);
|
|
|
|
+// List<String> result = new ArrayList<>();
|
|
|
|
+// synchronized (LATCH_COMM){
|
|
|
|
+// for (AMapZidingyiLocation element : lastAMapLocations){
|
|
|
|
+// result.add(0, element.toString()/*com.qx.wz.external.fastjson.JSONObject.toJSONString(element)*/);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// res.put("data",result);
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }catch(Exception ex){
|
|
|
|
+// code = "1";
|
|
|
|
+// msg = ex.getLocalizedMessage();
|
|
|
|
+// try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
+// Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// public ModuleResult sendAMapGis(){
|
|
|
|
+// JSONObject res = new JSONObject();
|
|
|
|
+// String code = "1";
|
|
|
|
+// String msg = "error";
|
|
|
|
+// try{
|
|
|
|
+// //TODO 启动服务相关判断
|
|
|
|
+// res.put("code",code);
|
|
|
|
+// res.put("msg",msg);
|
|
|
|
+// //初始化AMapLocationClientOption对象
|
|
|
|
+// mLocationOption = new AMapLocationClientOption();
|
|
|
|
+// AMapLocationClientOption option = new AMapLocationClientOption();
|
|
|
|
+// /**
|
|
|
|
+// * 设置定位场景,目前支持三种场景(签到、出行、运动,默认无场景)
|
|
|
|
+// */
|
|
|
|
+// option.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.SignIn);
|
|
|
|
+// if(null != mLocationClient){
|
|
|
|
+// mLocationClient.setLocationOption(option);
|
|
|
|
+// //设置场景模式后最好调用一次stop,再调用start以保证场景模式生效
|
|
|
|
+//// mLocationClient.stopLocation();
|
|
|
|
+//// mLocationClient.startLocation();
|
|
|
|
+//
|
|
|
|
+// //设置定位模式为AMapLocationMode.Hight_Accuracy,高精度模式。
|
|
|
|
+// mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
|
|
|
|
+//
|
|
|
|
+// //单位是毫秒,默认30000毫秒,建议超时时间不要低于8000毫秒。
|
|
|
|
+// mLocationOption.setHttpTimeOut(8000);
|
|
|
|
+//
|
|
|
|
+// //关闭缓存机制
|
|
|
|
+// mLocationOption.setLocationCacheEnable(false);
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// //给定位客户端对象设置定位参数
|
|
|
|
+// mLocationClient.setLocationOption(mLocationOption);
|
|
|
|
+//
|
|
|
|
+// code = "0";
|
|
|
|
+// msg = "success";
|
|
|
|
+// res.put("code",code);
|
|
|
|
+// res.put("msg",msg);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }catch(Exception ex){
|
|
|
|
+// code = "1";
|
|
|
|
+// msg = ex.getLocalizedMessage();
|
|
|
|
+// try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
+// Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// public ModuleResult startAMapGis(boolean onceFlag) {
|
|
|
|
+// JSONObject res = new JSONObject();
|
|
|
|
+// String code = "1";
|
|
|
|
+// String msg = "error";
|
|
|
|
+// try {
|
|
|
|
+// code = "0";
|
|
|
|
+// msg = "success";
|
|
|
|
+// res.put("code",code);
|
|
|
|
+// res.put("msg",msg);
|
|
|
|
+// if(onceFlag){
|
|
|
|
+// mStartedAMapLocation.set(true);
|
|
|
|
+// mLocationOption.setOnceLocation(true);
|
|
// mLocationClient.stopLocation();
|
|
// mLocationClient.stopLocation();
|
|
// mLocationClient.startLocation();
|
|
// mLocationClient.startLocation();
|
|
-
|
|
|
|
- //设置定位模式为AMapLocationMode.Hight_Accuracy,高精度模式。
|
|
|
|
- mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
|
|
|
|
-
|
|
|
|
- //单位是毫秒,默认30000毫秒,建议超时时间不要低于8000毫秒。
|
|
|
|
- mLocationOption.setHttpTimeOut(8000);
|
|
|
|
-
|
|
|
|
- //关闭缓存机制
|
|
|
|
- mLocationOption.setLocationCacheEnable(false);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //给定位客户端对象设置定位参数
|
|
|
|
- mLocationClient.setLocationOption(mLocationOption);
|
|
|
|
-
|
|
|
|
- code = "0";
|
|
|
|
- msg = "success";
|
|
|
|
- res.put("code",code);
|
|
|
|
- res.put("msg",msg);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }catch(Exception ex){
|
|
|
|
- code = "1";
|
|
|
|
- msg = ex.getLocalizedMessage();
|
|
|
|
- try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
- Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- public ModuleResult startAMapGis(boolean onceFlag) {
|
|
|
|
- JSONObject res = new JSONObject();
|
|
|
|
- String code = "1";
|
|
|
|
- String msg = "error";
|
|
|
|
- try {
|
|
|
|
- code = "0";
|
|
|
|
- msg = "success";
|
|
|
|
- res.put("code",code);
|
|
|
|
- res.put("msg",msg);
|
|
|
|
- if(onceFlag){
|
|
|
|
- mStartedAMapLocation.set(true);
|
|
|
|
- mLocationOption.setOnceLocation(true);
|
|
|
|
- mLocationClient.stopLocation();
|
|
|
|
- mLocationClient.startLocation();
|
|
|
|
- }else {
|
|
|
|
- //设置定位间隔,单位毫秒,默认为2000ms,最低1000ms。
|
|
|
|
- mLocationOption.setInterval(1000);
|
|
|
|
- mLocationClient.stopLocation();
|
|
|
|
- //启动定位
|
|
|
|
- mLocationClient.startLocation();
|
|
|
|
- }
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }catch(Exception ex){
|
|
|
|
- code = "1";
|
|
|
|
- msg = ex.getLocalizedMessage();
|
|
|
|
- try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
- Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- public ModuleResult stopAMapGis(){
|
|
|
|
- JSONObject res = new JSONObject();
|
|
|
|
- String code = "1";
|
|
|
|
- String msg = "error";
|
|
|
|
- try{
|
|
|
|
- //TODO 启动服务相关判断
|
|
|
|
- res.put("code",code);
|
|
|
|
- res.put("msg",msg);
|
|
|
|
- mLocationClient.stopLocation();//停止定位后,本地定位服务并不会被销毁
|
|
|
|
- mStartedAMapLocation.set(false);
|
|
|
|
- mWaitAMapSingleBack.set(false);
|
|
|
|
- code = "0";
|
|
|
|
- msg = "success";
|
|
|
|
- res.put("code",code);
|
|
|
|
- res.put("msg",msg);
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }catch(Exception ex){
|
|
|
|
- code = "1";
|
|
|
|
- msg = ex.getLocalizedMessage();
|
|
|
|
- try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
- Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
- return new ModuleResult(res);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+// }else {
|
|
|
|
+// //设置定位间隔,单位毫秒,默认为2000ms,最低1000ms。
|
|
|
|
+// mLocationOption.setInterval(1000);
|
|
|
|
+// mLocationClient.stopLocation();
|
|
|
|
+// //启动定位
|
|
|
|
+// mLocationClient.startLocation();
|
|
|
|
+// }
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }catch(Exception ex){
|
|
|
|
+// code = "1";
|
|
|
|
+// msg = ex.getLocalizedMessage();
|
|
|
|
+// try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
+// Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// public ModuleResult stopAMapGis(){
|
|
|
|
+// JSONObject res = new JSONObject();
|
|
|
|
+// String code = "1";
|
|
|
|
+// String msg = "error";
|
|
|
|
+// try{
|
|
|
|
+// //TODO 启动服务相关判断
|
|
|
|
+// res.put("code",code);
|
|
|
|
+// res.put("msg",msg);
|
|
|
|
+// mLocationClient.stopLocation();//停止定位后,本地定位服务并不会被销毁
|
|
|
|
+// mStartedAMapLocation.set(false);
|
|
|
|
+// mWaitAMapSingleBack.set(false);
|
|
|
|
+// code = "0";
|
|
|
|
+// msg = "success";
|
|
|
|
+// res.put("code",code);
|
|
|
|
+// res.put("msg",msg);
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }catch(Exception ex){
|
|
|
|
+// code = "1";
|
|
|
|
+// msg = ex.getLocalizedMessage();
|
|
|
|
+// try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
|
+// Log.e(TAG,ex.getLocalizedMessage());
|
|
|
|
+// return new ModuleResult(res);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
|
|
///////////////////////以下为百度定位//////////////////////
|
|
///////////////////////以下为百度定位//////////////////////
|
|
|
|
+ private final byte[] LATCH_COMM = new byte[0];
|
|
class BMapLocationResult{
|
|
class BMapLocationResult{
|
|
int code = 1; //0--成功;非0--失败
|
|
int code = 1; //0--成功;非0--失败
|
|
long acceptTime = 0L; //接收高德定位回调的时间
|
|
long acceptTime = 0L; //接收高德定位回调的时间
|
|
@@ -1685,7 +1690,7 @@ public class APIModuleGis extends UZModule {
|
|
}
|
|
}
|
|
if (mWaitBMapSingleBack.compareAndSet(true, false)){
|
|
if (mWaitBMapSingleBack.compareAndSet(true, false)){
|
|
if (mBMapClient != null && locationSize >= 10){
|
|
if (mBMapClient != null && locationSize >= 10){
|
|
- mBMapClient.stop();
|
|
|
|
|
|
+// mBMapClient.stop();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1702,7 +1707,7 @@ public class APIModuleGis extends UZModule {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- public void initBMapFun(UZModuleContext moduleContext){
|
|
|
|
|
|
+ public void initBMapFun(UZModuleContext moduleContext) throws Exception{
|
|
if (mBMapClient != null) {
|
|
if (mBMapClient != null) {
|
|
mBMapClient.stop();
|
|
mBMapClient.stop();
|
|
|
|
|
|
@@ -1723,7 +1728,7 @@ public class APIModuleGis extends UZModule {
|
|
mBMapOption.setIgnoreKillProcess(true);
|
|
mBMapOption.setIgnoreKillProcess(true);
|
|
mBMapOption.setIsNeedLocationPoiList(false);
|
|
mBMapOption.setIsNeedLocationPoiList(false);
|
|
mBMapOption.SetIgnoreCacheException(false);
|
|
mBMapOption.SetIgnoreCacheException(false);
|
|
- mBMapOption.setLocationMode(LocationMode.Hight_Accuracy);
|
|
|
|
|
|
+ mBMapOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
|
|
mBMapOption.setIsNeedAltitude(false);
|
|
mBMapOption.setIsNeedAltitude(false);
|
|
mBMapOption.setFirstLocType(LocationClientOption.FirstLocType.SPEED_IN_FIRST_LOC);
|
|
mBMapOption.setFirstLocType(LocationClientOption.FirstLocType.SPEED_IN_FIRST_LOC);
|
|
mBMapOption.setOpenGnss(true);
|
|
mBMapOption.setOpenGnss(true);
|
|
@@ -1743,7 +1748,7 @@ public class APIModuleGis extends UZModule {
|
|
mBMapOption.setScanSpan(0);
|
|
mBMapOption.setScanSpan(0);
|
|
mBMapOption.setLocationNotify(false);
|
|
mBMapOption.setLocationNotify(false);
|
|
mBMapOption.setWifiCacheTimeOut(10000);
|
|
mBMapOption.setWifiCacheTimeOut(10000);
|
|
- mBMapOption.setFirstLocType(LocationClientOption.FirstLocType.ACCUARACY_IN_FIRST_LOC);
|
|
|
|
|
|
+ mBMapOption.setFirstLocType(LocationClientOption.FirstLocType.ACCURACY_IN_FIRST_LOC);
|
|
|
|
|
|
mBMapClient.stop();
|
|
mBMapClient.stop();
|
|
mBMapClient.setLocOption(mBMapOption);
|
|
mBMapClient.setLocOption(mBMapOption);
|