Cordova插件开发:集成南方测绘RTK实现高精度卫星定位

本文介绍了如何通过Cordova插件集成南方测绘RTK,实现高精度卫星定位功能。内容包括:效果预览、坐标展示、封装的公共类utilsTools、南方测绘坐标获取的封装、插件JS和Java方法的封装,详细讲解了如何在Android平台上进行操作,同时提及了对其他RTK厂家的拓展可能性。
摘要由CSDN通过智能技术生成

1.最终效果预览

说明:南方测绘RTK设备厂家提供的SDK中封装了蓝牙搜索连接、Cross账号登录等功能,我们通过Cordova插件进一步封装以便于我们可以在js中调用,目前项中实现了普通手机坐标定位(高德)、高精度差分设备模块定位(卫星数据)、手机获取南方测绘RTK硬件设备定位(蓝牙连接)这几种方式,后续应该会对接更多的RTK厂家。

2.页面持续展示获取的坐标

        let dTValue = localStorage.getItem("deviceType") || "0"
        if (parseInt(dTValue) > 1) {
            this.isHighPrecision = true
            let obj = Object.assign({}, this.mapConfig.mapLocationObj)
            obj.isKeepCallBack = true
            let res = await this.utilsTools.getXYLocationDataByDeviceType(obj)
            if (res && res["code"] == "200") {
                this.showHighData(res)
            }
        } else {
            this.isHighPrecision = false
        }

说明:isHighPrecision为true页面顶部展示经纬度及高程模块,其他模式不展示,模式的设定单独一个页面,不同的模式存值deviceType不同,并且要方便之后拓展对接不同的厂商,获取到坐标数据res后我们将数据传递到showHighData方法中在页面展示,在mapLocationObj中配置了插件封装的参数,示例如下

public mapLocationObj = {
		packageName: 'com.xxx.xxx',
		delayTime: 300,
		intervalTime: 500,
		rodHeight: '0.0',
		isKeepCallBack: false,
		paramKey: 'getKeepData'
	}

目前插件定义了六个值,并且之后扩展的话直接加参数就行,delayTime为插件请求方法的延迟时间,intervalTime为请求插件的间隔时间,rodHeight可作为页面设置杆高数值,isKeepCallBack为true表示持续返回坐标数据,false表示只获取一次坐标数据,paramKey参数的值代表执行插件中不同的方法

3.公共类utilsTools中封装得获取坐标方法

async getXYLocationDataByDeviceType(obj) {
		let res;
		if (this.isAndroid()) {
			if (localStorage.getItem('deviceType') == '2') {
				res = await this.returnNmeaDataNew(obj)
			} else if (localStorage.getItem('deviceType') == '3') {
				res = await this.settingRTKLocation(obj)
			} else {
				res = await this.returnGaoDeData()
			}
		} else {
			res = {
				latitude: 0,
				longitude: 0,
				altitude: 0,
				gpsStatue: 0,
				code: 500,
			}
		}
		return res
	}

目前插件只开发Android版本,浏览器或者IOS返回默认值0,当deviceType为3我们调用了南方测绘RTK获取坐标方式

4.南方测绘坐标获取封装

settingRTKLocation(obj) {
    return new Promise((resolve, reject) => {
		        RTKlocationManager.settingRTKLocation(obj, res => {
				      resolve(res)
			    }, fail => {
				    reject(fail)
			    })
		    });
	   }

5.插件js方法封装

settingRTKLocation:function(options,onSuccess,onError){
			exec(onSuccess, onError, "RTKlocationManager", "settingRTKLocation", [options]);
	}

6.Java方法封装

方法入口

 public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if("settingRTKLocation".equals(action)){
            message = args.getJSONObject(0);
            isKeepCallBack = message.getBoolean("isKeepCallBack")||false;
            paramKey =  message.getString("paramKey");
            this.getLocation();
            this.goPageByParam(callbackContext,paramKey);
            return true;
        }
        return false;
    }

根据参数不同调用不同的方法

  private void goPageByParam(CallbackContext callbackContext, String key){
        singleLocaitonCC = callbackContext;
        switch (key) {
            case "connected":
                SdkServiceApi.startConnectedActivity();
                break;
            ......
            case "getKeepData":
                updateView();
                break;
        }

    }

更新坐标数据

void updateView() {
        String s = "解状态:";
        switch (gpsStatue) {
            case 0:
                s += "无效解";
                break;
            case 1:
                s += "单点解";
                break;
            case 2:
                s += "差分解";
                break;
            case 4:
                s += "固定解";
                break;
            case 5:
                s += "浮点解";
                break;
        }
        gpsStatueStr = s;
        try {
            if (null != singleLocaitonCC) {
                PositionInfo();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

实现单次定位委托

    public void PositionInfo() throws JSONException {
        sendPositionInfo(singleLocaitonCC);
    }

返回定位数据

   public void sendPositionInfo(CallbackContext c) throws JSONException {
        if(0.0 == latitude){
            try {
                Thread.sleep(delayTime);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if(!isKeepCallBack){
            locationDestory();
        }
        JSONObject json = new JSONObject();
        json.put("latitude",latitude);
        json.put("longitude",longitude);
        json.put("altitude",altitude);
		      json.put("hrms",hrms);
		      json.put("vrms",vrms);
		      json.put("rms",rms);
        json.put("type","rtkGps");
		      json.put("gpsStatue",gpsStatue);
        if (0.0 != latitude) {
            json.put("code", "200");
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
            pluginResult.setKeepCallback(isKeepCallBack);
            c.sendPluginResult(pluginResult);
        } else {
            json.put("code", "500");
            PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, json);
            pluginResult.setKeepCallback(isKeepCallBack);
            c.sendPluginResult(pluginResult);
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

博主逸尘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值