更新记录

1.0.1(2022-12-12)

1、调整定位成功返回参数 2、添加iOS支持

1.0.0(2022-12-06)

添加百度持续定位功能


平台兼容性

Android Android CPU类型 iOS
适用版本区间:5.1 - 12.0 armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 适用版本区间:12 - 15

原生插件通用使用流程:

  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原生插件配置”->”云端插件“列表中删除该插件重新选择


Uni-App原生插件集成文档

简介

集成此原生插件以获得百度地图相关能力

云打包iOS前,要需要申请后台运行权限,在manifest.json中配置location,参考https://ask.dcloud.net.cn/article/36430


初始化插件

var locator = uni.requireNativePlugin('bmk-locator');

设置持续定位的回调

locator.setReceivedLocationCallback((ret)=> {
                uni.showToast({
                    title:'结果:' + JSON.stringify(ret),
                    icon: "none"
                })
            });

传入参数:

回调参数:

{
"data": {
    "countryCode": "0",
    "country": "中国",
    "province": "江苏省",
    "city": "南京市",
    "cityCode": "315",
    "district": "溧水区",
    "town": "柘塘街道",
    "street": "机场路",
    "streetNumber": "",
    "adcode": "320117",
    "latitude": 31.681433,
    "longitude": 119.020072,
    "altitude": 5e-324
},
"code": "0",
"msg": "GPS位置有更新"

}

示例:

<template>
    <view class="content">
        <view class="btn-row">
            <button v-if="!hasLogin" type="primary" class="primary" @tap="bindLogin">获取地址详细信息</button>
        </view>
    </view>
</template>
<script>
    import {
        mapState,
        mapMutations
    } from 'vuex'

    export default {
        computed: {
            ...mapState(['hasLogin', 'forcedLogin'])
        },
        methods: {
            ...mapMutations(['logout']),
            bindLogin() {
                var locator = uni.requireNativePlugin('bmk-locator');
                locator.setReceivedLocationCallback((ret)=> {
                uni.showToast({
                    title:'结果:' + JSON.stringify(ret),
                    icon: "none"
                })
            });
            });
            }
        }
    }
</script>
<style>
</style>

开始定位:

locator.startUpdatingLocation({}, (ret)=> {
                uni.showToast({
                    title:'结果:' + JSON.stringify(ret),
                    icon: "none"
                })
            });

传入参数:

{}

回调参数:

{
    "message": "",          // 错误描述
    "code": "0"         // code:0,非零为对应错误码
}

示例:

<template>
        <view class="content">
            <view class="btn-row">
                <button v-if="!hasLogin" type="primary" class="primary" @tap="bindLogin">测试步行导航</button>
            </view>
        </view>
    </template>
    <script>
        import {
            mapState,
            mapMutations
        } from 'vuex'

        export default {
            computed: {
                ...mapState(['hasLogin', 'forcedLogin'])
            },
            methods: {
                ...mapMutations(['logout']),
                bindLogin() {
                    var locator = uni.requireNativePlugin('bmk-locator');
                    locator.startUpdatingLocation({}, (ret)=> {
                uni.showToast({
                    title:'结果:' + JSON.stringify(ret),
                    icon: "none"
                })
            });
                }
            }
        }
    </script>
    <style>
    </style>

停止定位:

locator.stopUpdatingLocation((ret)=> {
                uni.showToast({
                    title:'结果:' + JSON.stringify(ret),
                    icon: "none"
                })
            });

传入参数:

{}

回调参数:

{
    "message": "",      // 错误描述
    "code": "0"         // code:0,非零为对应错误码
}

示例:

<template>
        <view class="content">
            <view class="btn-row">
                <button v-if="!hasLogin" type="primary" class="primary" @tap="bindLogin">测试步行导航</button>
            </view>
        </view>
    </template>
    <script>
        import {
            mapState,
            mapMutations
        } from 'vuex'

        export default {
            computed: {
                ...mapState(['hasLogin', 'forcedLogin'])
            },
            methods: {
                ...mapMutations(['logout']),
                bindLogin() {
                    var locator = uni.requireNativePlugin('bmk-locator');
                    locator.stopUpdatingLocation((ret)=> {
                uni.showToast({
                    title:'结果:' + JSON.stringify(ret),
                    icon: "none"
                })
            });
                }
            }
        }
    </script>
    <style>
    </style>

隐私、权限声明

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

定位权限

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

插件使用的百度定位SDK会采集数据,详情可参考:https://lbsyun.baidu.com/index.php?title=openprivacy

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

许可协议

作者未提供license.md

暂无用户评论。

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