Skip to content

支付宝小程序集成API

1、小程序开发设置

1.1 服务器域名白名单

https://a.brtmap.com;
https://files.brtmap.com;
https://map-sdk.brtmap.com;

2、下载小程序端 - JS-SDK

下载 brtloc.miniprogram.js 下载到本地后放到您自己小程序项目里面

.

3、开始使用

​ 说明:使用小程序扫描ibeacon接口,通过 API my.createWebViewContext() 消息 发送给H5实现定位

3.1 引入SDK

javascript
// 引入sdk
const brtloc = require('/brtloc.miniprogram.js');

3.2 创建实例

javascript
// 您的建筑ID
let buildingID = '';
// 建筑token
let token = '';

// 实例
let $locate = new brtloc.Location({
    alipayContext: my.createWebViewContext('web-view'),
    buildingID,
    token
});

3.3 ibeacon扫描

javascript
// ready
$locate.on('ready', () => {
    // 监听扫描ibeacon
    my.onBeaconUpdate(res => {
        // 分析beacons, 计算定位点
        $locate.beaconAnalysis(res.beacons);
    });

    //开启 ibeacon扫描
    my.startBeaconDiscovery({
        uuids: $locate.uuids, // $locate.uuids 是智石默认的uuids  请及时修改。
        success: res => {}
    });
});

3.4 监听定位点

javascript
// 计算后的定位点
$locate.on('location', point => {
	console.log('point', point);
});

3.5 完整示例

.axml

javascript
<web-view id="web-view" src="{{url}}" />

.js

javascript
// 引入sdk
const brtloc = require('/brtloc.miniprogram.js');

// 您的建筑ID
const buildingID = '';
// 有效token
const token = '';

Page({
    data: {
        // 待打开的H5链接
        url: ''
    },
    onLoad: function () {
        // 实例
        let $locate = new brtloc.Location({
    		alipayContext: my.createWebViewContext('web-view'),
            buildingID,
            token
        });

        // ready
        $locate.on('ready', () => {
            // 监听扫描ibeacon
            my.onBeaconUpdate(res => {
                $locate.beaconAnalysis(res.beacons);
            });

            //开启 ibeacon扫描
            my.startBeaconDiscovery({
                uuids: $locate.uuids,
                success: res => {}
            });

        });

        // 监听 实时的定位点
        $locate.on('location', point => {
            console.log('point', point);
        });

        // 设置H5链接
        this.setData({
            url: '//127.0.0.1:8080/demo.html'
        });

    }
})

4、API

4.1 brtloc

NameTypeDescription
LocationFunction定位实例化

Location

javascript
new brtloc.Loaction(options:object);

4.2 Parameters -> Options

NameTypeDefaultDescription
alipayContextwebViewContentnull创建与H5的通信方法
buildingIDStringnull地图建筑ID
tokenStringnull地图有效token
uuidsArray[]iBeacon的uuid

4.3 Instance Members

NameDescription
beaconAnalysis(beacons)分析扫描的beacons
reset()刷新定位点
on(type, function)监听
once(type, function)只监听一次
off(type, function)移除监听

4.4 Events

NameDescription
ready准备完毕
location实时定位点
beacons分析后的有效beacons