更新记录

1.0.0(2023-03-22)

新版首发


平台兼容性

Android Android CPU类型 iOS
适用版本区间:4.4 - 12.0 armeabi-v7a:支持,arm64-v8a:支持,x86:支持 适用版本区间:11 - 16

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


KJ-GeoFence

高德地图定位扩展、地理围栏、电子围栏

注意事项

1.manifest.json -> app模块配置 -> 定位 -> 高德地图 勾选  配置正确key
2.manifest.json -> app模块配置 -> Maps -> 高德地图 勾选  配置正确key
3.需要定位权限
4.需要精确位置
5.ios需要后台定位,需要配置manifest.json->App常用其它设置->后台运行能力 location

使用

<template>
    <view class="content">
        <map style="width: 0;height: 0;">注意:需要放置map,执行配置key和隐私政策</map>
        <view class="title">----权限-----</view>
        <button type="primary" @click="judgePermission">判断是否有定位权限(ios)</button>
        <button type="primary" @click="requestPermission">请求定位权限(ios)</button>
        <button type="primary" @click="gotoLocationSetting">跳转定位设置页面</button>
        <view class="title">----初始化-----</view>
        <button type="primary" @click="init">初始化</button>
        <view class="title">----创建围栏-----</view>
        <button type="primary" @click="addKeywordPOIRegion">根据关键字创建围栏</button>
        <button type="primary" @click="addAroundPOIRegion">根据周边POI创建围栏</button>
        <button type="primary" @click="addDistrictRegion">创建行政区域围栏</button>
        <button type="primary" @click="addCircleRegion">创建自定义圆形围栏</button>
        <button type="primary" @click="addPolygonRegion">创建自定义多边形围栏</button>
        <view class="title">----查询围栏-----</view>
        <button type="primary" @click="getAllGeoFence">获得所有围栏(andorid)</button>
        <button type="primary" @click="getGeoFenceRegions">获得已经注册的围栏(ios)</button>
        <button type="primary" @click="getMonitoringGeoFenceRegions">获得正在监控的围栏(ios)</button>
        <button type="primary" @click="getPausedGeoFenceRegions">获得已经暂停的围栏(ios)</button>
        <view class="title">----围栏状态、暂停/开始围栏-----</view>
        <button type="primary" @click="isPause">围栏是否暂停(android)</button>
        <button type="primary" @click="pauseGeoFence">暂停围栏(android)</button>
        <button type="primary" @click="resumeGeoFence">恢复围栏(android)</button>
        <button type="primary" @click="setGeoFenceAble">设置围栏是否生效(android)</button>
        <button type="primary" @click="getGeoFenceRegionStatus">获取指定围栏的运行状态(ios)</button>
        <button type="primary" @click="pauseGeoFenceRegions">暂停指定customID的围栏(ios)</button>
        <button type="primary" @click="pauseTheGeoFenceRegion">暂停指定围栏(ios)</button>
        <button type="primary" @click="startGeoFenceRegions">根据customID开始监控已经暂停的围栏(ios)</button>
        <button type="primary" @click="startTheGeoFenceRegion">开始监控指定围栏(ios)</button>
        <view class="title">----移除围栏-----</view>
        <button type="primary" @click="removeTheGeoFenceRegion">移除指定围栏(ios)</button>
        <button type="primary" @click="removeGeoFenceRegions">移除指定customID的围栏(ios)</button>
        <button type="primary" @click="removeAllGeoFenceRegions">移除所有围栏</button>
    </view>
</template>

<script>
    const KJGeoFence = uni.requireNativePlugin('KJ-GeoFence');
    export default {
        data() {
            return {
                title: 'Hello'
            }
        },
        onLoad() {
            if (plus.os.name == 'Android') {
                plus.android.requestPermissions(
                    ['android.permission.ACCESS_FINE_LOCATION',
                        'android.permission.ACCESS_COARSE_LOCATION'
                    ],
                    function(resultObj) {
                        var result = 0;
                        for (var i = 0; i < resultObj.granted.length; i++) {
                            var grantedPermission = resultObj.granted[i];
                            console.log('已获取的权限:' + grantedPermission);
                            result = 1
                        }
                        for (var i = 0; i < resultObj.deniedPresent.length; i++) {
                            var deniedPresentPermission = resultObj.deniedPresent[i];
                            console.log('拒绝本次申请的权限:' + deniedPresentPermission);
                            result = 0
                        }
                        for (var i = 0; i < resultObj.deniedAlways.length; i++) {
                            var deniedAlwaysPermission = resultObj.deniedAlways[i];
                            console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
                            result = -1
                        }
                    },
                    function(error) {
                        console.log('申请权限错误:' + error.code + " = " + error.message);
                    }
                );
            }
            var globalEvent = uni.requireNativePlugin('globalEvent');
            globalEvent.addEventListener('geoFenceCallBack', function(res) {
                console.log('geoFenceCallBack' + JSON.stringify(res));
                if (res.method == "onGeoFenceCreateFinished") {
                    console.log("添加地理围栏完成")
                    /**
                     * 返回json字段说明:
                     * customID - 用户自定义ID
                     * ios:
                     * {"method":"onGeoFenceCreateFinished","customID":"poi_1","regions":[{"currentLocation":{"longitude":0,"latitude":0},
                     * "regionType":2,"customID":"poi_1","identifier":"A1816549-BDF8-4F12-BF2E-0AEC3A05CF09","
                     * poiRegion":{"POIItem":{"address":"广州塔","location":{"longitude":113.324553,"latitude":23.106414},"typeCode":[],"city":[],"district":[],"tel":[],
                     * "type":[],"name":"广东省广州市海珠区广州塔","province":[]}},"fenceStatus":0}],"error":null}
                     * regions - 地理围栏信息
                     * regionType - 地理围栏类型 0(圆形地理围栏) 1(多边形地理围栏) 2(兴趣点(POI)地理围栏) 3(行政区划地理围栏)
                     * identifier - 唯一标识符
                     * fenceStatus - 用户的位置和围栏的关系 0(未知) 1(进入围栏) 2(离开围栏) 3(停留在地理围栏内10分钟)
                     * poiRegion - poi围栏相关信息
                     * circleRegion - 圆形围栏相关信息 
                     * polygonRegion - 多边形围栏相关信息
                     * districtRegion - 行政区围栏相关信息
                     * andoird:
                     * {"customID":"poi_1","errorCode":0,"geoFenceList":[{"fenceId":"346913142","customId":"poi_1","status":0,
                     * "pointList":[[{"longitude":113.324553,"latitude":23.106414}]],"activatesAction":7,"center":{"longitude":113.324553,
                     * "latitude":23.106414},"type":2,"isAble":true,"poiItem":{"typeCode":"[]","poiId":"","tel":"[]","latitude":23.106414,
                     * "longitude":113.324553,"poiName":"广东省广州市海珠区广州塔","province":"[]","poiType":"[]","address":"广州塔","adname":"[]","city":"[]"}}],
                     * "method":"onGeoFenceCreateFinished"}
                     * errorCode - 错误码
                     * 
                     * geoFenceList - 地理围栏信息
                     * fenceId - 地理围栏的ID
                     * status - 围栏的状态 0(未知) 1(进入围栏) 2(离开围栏) 4(停留在地理围栏内10分钟)
                     * pointList - 围栏坐标点
                     * activatesAction - 地理围栏触发条件
                     * center - 围栏中心点坐标
                     * type - 地理围栏类型 0(圆形地理围栏) 1(多边形地理围栏) 2(兴趣点(POI)地理围栏) 3(行政区划地理围栏)
                     * isAble - 围栏是否可用
                     * */
                } else if (res.method == "onGeoFencesStatusChanged") {
                    console.log("地理围栏状态改变")
                    /**
                     * 返回json字段说明:
                     * customID - 用户自定义ID
                     * ios:
                     * {"error":null,"method":"onGeoFencesStatusChanged","region":{"currentLocation":{"longitude":113.2867982313368,
                     * "latitude":23.074051920572916},"regionType":2,"customID":"poi_1","identifier":"CA9025BA-0E16-48E5-A7CB-ECDC0ACE9F18",
                     * "poiRegion":{"POIItem":{"address":"广州塔","location":{"longitude":113.324553,"latitude":23.106414},"typeCode":[],"city":[],
                     * "district":[],"tel":[],"type":[],"name":"广东省广州市海珠区广州塔","province":[]}},"fenceStatus":2}}
                     * region - 地理围栏信息
                     * regionType - 地理围栏类型 0(圆形地理围栏) 1(多边形地理围栏) 2(兴趣点(POI)地理围栏) 3(行政区划地理围栏)
                     * identifier - 唯一标识符
                     * fenceStatus - 用户的位置和围栏的关系 0(未知) 1(进入围栏) 2(离开围栏) 3(停留在地理围栏内10分钟)
                     * poiRegion - poi围栏相关信息
                     * circleRegion - 圆形围栏相关信息 
                     * polygonRegion - 多边形围栏相关信息
                     * districtRegion - 行政区围栏相关信息
                     * andoird:
                     * {"status":2,"customID":"poi_1","fenceID":"348069906","method":"onGeoFencesStatusChanged","geoFence":
                     * {"fenceId":"348069906","customId":"poi_1","status":2,"pointList":[[{"longitude":113.324553,"latitude":23.106414}]],
                     * "activatesAction":7,"center":{"longitude":113.324553,"latitude":23.106414},"type":2,"isAble":true,"poiItem":{"typeCode":"[]",
                     * "poiId":"","tel":"[]","latitude":23.106414,"longitude":113.324553,"poiName":"广东省广州市海珠区广州塔","province":"[]","poiType":"[]",
                     * "address":"广州塔","adname":"[]","city":"[]"}}}
                     * 
                     * errorCode - 错误码 0(创建地理围栏成功) 1(参数错误) 4(网络连接异常) 5(解析数据失败(有可能是连接的需要登录的网络但是没有登录))
                     * 7(鉴权失败) 8(其他未知错误) 16(无可用地理围栏) 
                     * 17(相同的围栏已经存在,无需重复添加 当地理围栏的customID,半径,周边点(多边形),中心点坐标(圆形)这几个属性完全一致时,则认为是相同围栏)
                     * 
                     * geoFence - 地理围栏信息
                     * fenceId - 地理围栏的ID
                     * status - 围栏的状态 0(未知) 1(进入围栏) 2(离开围栏) 4(停留在地理围栏内10分钟)
                     * pointList - 围栏坐标点
                     * activatesAction - 地理围栏触发条件
                     * center - 围栏中心点坐标
                     * type - 地理围栏类型 0(圆形地理围栏) 1(多边形地理围栏) 2(兴趣点(POI)地理围栏) 3(行政区划地理围栏)
                     * isAble - 围栏是否可用
                     * */
                }
            });
            this.init();
        },
        methods: {
            judgePermission() {
                KJGeoFence.judgePermission((res) => {
                    console.log("judgePermission:" + JSON.stringify(res));
                    /**
                     * 返回json字段说明:{"result":true,"status":3}
                     * result:是否授权
                     * status:0-还没决定 1-受限制 2-拒绝 3、4、5-已授权
                     * */
                })
            },
            requestPermission() {
                KJGeoFence.requestPermission()
            },
            gotoLocationSetting() {
                KJGeoFence.gotoLocationSetting();
            },
            init() {
                /**
                 * activeAction - 地理围栏监听状态 
                 * andorid:1(进入围栏) 2(离开围栏) 4(停留在地理围栏内10分钟)
                 * ios:1 << 0(进入围栏) 1 << 1(离开围栏) 1 << 2(停留在地理围栏内10分钟)
                 * */
                var dic;
                if (plus.os.name == 'Android') {
                    dic = {
                        "activeAction": 1 | 2 | 4
                    };
                } else {
                    dic = {
                        "pausesLocationUpdatesAutomatically": false, //ios才有效,定位是否会被系统自动暂停
                        "allowsBackgroundLocationUpdates": false, //ios才有效,//是否开启后台定位,为true 需要配置manifest.json->App常用其它设置->后台运行能力 location
                        "detectRiskOfFakeLocation": true, //ios才有效,检测是否存在虚拟定位风险
                        "activeAction": 1 << 0 | 1 << 1 | 1 << 2
                    };
                }
                KJGeoFence.init(dic, (res) => {
                    console.log("init:" + JSON.stringify(res));
                })
            },
            addKeywordPOIRegion() {
                var dic = {
                    "keyword": "广州塔", //POI关键字
                    "poiType": "景区", //POI类型
                    "city": "广州市", //POI所在的城市名称
                    "size": 20, //要查询的数据的条数 0-25
                    "customID": "poi_1" //用户自定义ID
                };
                KJGeoFence.addKeywordPOIRegion(dic, (res) => {
                    console.log("addKeywordPOIRegion:" + JSON.stringify(res));
                })
            },
            addAroundPOIRegion() {
                var dic = {
                    "locationPoint": { //周边区域中心点的经纬度,以此中心点建立周边地理围栏
                        "latitude": 23.176514,
                        "longitude": 113.238836,
                    },
                    "aroundRadius": 3000, //周边半径,0-50000米,这个是搜索半径,不是建立的围栏的半径
                    "keyword": "广州塔", //POI关键字
                    "poiType": "景区", //POI类型
                    "city": "广州市", //POI所在的城市名称
                    "size": 20, //要查询的数据的条数 0-25
                    "customID": "poi_2" //用户自定义ID
                };
                KJGeoFence.addAroundPOIRegion(dic, (res) => {
                    console.log("addAroundPOIRegion:" + JSON.stringify(res));
                })
            },
            addDistrictRegion() {
                var dic = {
                    "districtName": "海珠区", //区域名称
                    "customID": "district_1" //用户自定义ID
                };
                KJGeoFence.addDistrictRegion(dic, (res) => {
                    console.log("addDistrictRegion:" + JSON.stringify(res));
                })
            },
            addCircleRegion() {
                var dic = {
                    "center": { //围栏中心点的经纬度
                        "latitude": 23.176514,
                        "longitude": 113.238836,
                    },
                    "radius": 300, //创建的围栏的半径,半径大于0,单位米
                    "customID": "circle_1" //用户自定义ID
                };
                KJGeoFence.addCircleRegion(dic, (res) => {
                    console.log("addCircleRegion:" + JSON.stringify(res));
                })
            },
            addPolygonRegion() {
                var dic = {
                    "coordinates": [{ //经纬度坐标点数据,最少3个点
                        "latitude": 23.237925,
                        "longitude": 113.177899,
                    }, {
                        "latitude": 23.236965,
                        "longitude": 113.175231,
                    }, {
                        "latitude": 23.239583,
                        "longitude": 113.174876,
                    }, {
                        "latitude": 23.240462,
                        "longitude": 113.17746,
                    }],
                    "customID": "polygon_1" //用户自定义ID
                };
                KJGeoFence.addPolygonRegion(dic, (res) => {
                    console.log("addPolygonRegion:" + JSON.stringify(res));
                })
            },
            getAllGeoFence() {
                KJGeoFence.getAllGeoFence((res) => {
                    console.log("getAllGeoFence:" + JSON.stringify(res));
                })
            },
            getGeoFenceRegions() {
                var dic = {
                    "customID": null //用户自定义ID,为null查询所有
                };
                KJGeoFence.getGeoFenceRegions(dic, (res) => {
                    console.log("getGeoFenceRegions:" + JSON.stringify(res));
                })
            },
            getMonitoringGeoFenceRegions() {
                var dic = {
                    "customID": null //用户自定义ID,为null查询所有
                };
                KJGeoFence.getMonitoringGeoFenceRegions(dic, (res) => {
                    console.log("getMonitoringGeoFenceRegions:" + JSON.stringify(res));
                })
            },
            getPausedGeoFenceRegions() {
                var dic = {
                    "customID": null //用户自定义ID,为null查询所有
                };
                KJGeoFence.getPausedGeoFenceRegions(dic, (res) => {
                    console.log("getPausedGeoFenceRegions:" + JSON.stringify(res));
                })
            },
            isPause() {
                KJGeoFence.isPause((res) => {
                    console.log("isPause:" + JSON.stringify(res));
                })
            },
            pauseGeoFence() {
                KJGeoFence.pauseGeoFence((res) => {
                    console.log("pauseGeoFence:" + JSON.stringify(res));
                })
            },
            resumeGeoFence() {
                KJGeoFence.resumeGeoFence((res) => {
                    console.log("resumeGeoFence:" + JSON.stringify(res));
                })
            },
            resumeGeoFence() {
                KJGeoFence.resumeGeoFence((res) => {
                    console.log("resumeGeoFence:" + JSON.stringify(res));
                })
            },
            setGeoFenceAble() {
                var dic = {
                    "fenceId": "", //地理围栏的fenceId
                    "able": false
                };
                KJGeoFence.getGeoFenceRegionStatus(dic, (res) => {
                    console.log("getGeoFenceRegionStatus:" + JSON.stringify(res));
                })
            },
            getGeoFenceRegionStatus() {
                var dic = {
                    "identifier": "" //用户自定义ID
                };
                KJGeoFence.getGeoFenceRegionStatus(dic, (res) => {
                    console.log("getGeoFenceRegionStatus:" + JSON.stringify(res));
                })
            },
            pauseGeoFenceRegions() {
                var dic = {
                    "customID": "polygon_1" //用户自定义ID
                };
                KJGeoFence.pauseGeoFenceRegions(dic, (res) => {
                    console.log("pauseGeoFenceRegions:" + JSON.stringify(res));
                })
            },
            pauseTheGeoFenceRegion() {
                var dic = {
                    "identifier": "" //唯一标识符
                };
                KJGeoFence.pauseGeoFenceRegions(dic, (res) => {
                    console.log("pauseGeoFenceRegions:" + JSON.stringify(res));
                })
            },
            startGeoFenceRegions() {
                var dic = {
                    "customID": "polygon_1" //用户自定义ID
                };
                KJGeoFence.startGeoFenceRegions(dic, (res) => {
                    console.log("startGeoFenceRegions:" + JSON.stringify(res));
                })
            },
            startTheGeoFenceRegion() {
                var dic = {
                    "identifier": "" //唯一标识符
                };
                KJGeoFence.startTheGeoFenceRegion(dic, (res) => {
                    console.log("startTheGeoFenceRegion:" + JSON.stringify(res));
                })
            },
            removeTheGeoFenceRegion() {
                var dic = {
                    "identifier": "" //唯一标识符
                };
                KJGeoFence.removeTheGeoFenceRegion(dic, (res) => {
                    console.log("removeTheGeoFenceRegion:" + JSON.stringify(res));
                })
            },
            removeGeoFenceRegions() {
                var dic = {
                    "customID": "poi_1" //用户自定义ID
                };
                KJGeoFence.removeGeoFenceRegions(dic, (res) => {
                    console.log("removeGeoFenceRegions:" + JSON.stringify(res));
                })
            },
            removeAllGeoFenceRegions() {
                KJGeoFence.removeAllGeoFenceRegions((res) => {
                    console.log("removeAllGeoFenceRegions:" + JSON.stringify(res));
                })
            }
        }
    }
</script>
<style>
    button {
        font-size: 15px;
    }

    .title {
        text-align: center;
    }
</style>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

ios需要定位权限,andorid:android.permission.ACCESS_FINE_LOCATION、android.permission.ACCESS_COARSE_LOCATION

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件自身不采集任何数据,插件使用的高德地图 SDK采集数据请参考其官方说明:https://lbs.amap.com

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问