(以“<div id="examples_center"> <!-- 页面标题 --> <div class="title-hd">圆形服务地理围栏(围栏报警推送)</div> <!-- 标题下子标题及...”为内容创建页面) |
|||
第1行: | 第1行: | ||
− | <div id="examples_center"> | + | <div id="examples_center"><!-- 页面标题 --><div class="title-hd">地理围栏</div><!-- 标题下子标题及简介,可有多个 --><div class="title-mi">注意</div><div class="wrap-mi">下面的接口介绍创建围栏示例代码以圆形服务围栏为例,多边形围栏、线型围栏 可下载demo 参考</div><!-- --></div><div class="demos_wrap"><div class="header"><div class="andiord-header active">Android</div><div class="ios-header">iOS</div></div><div class="andiord-wrap wrap"><div class="wrap-wp"><div class="wrap_left"><div class="left-video"><div class="img-bg-and"></div><div class="phone-android"><div class="video-wrap infor"><div class="video-control"></div><!-- 安卓视频位置 (不写协议)--><pre>//mapopen-website-wiki.cdn.bcebos.com/demos/andDemos/yingyan/地理围栏.mp4</pre> |
− | + | </div><div class="video-icon-and"><div class="play play-and"></div><div class="stop stop-and"></div></div></div><div class="progressWrap-hide-and"></div><div id="videoControls-and"><div id="progressWrap-and"><div id="playProgress-and"></div></div></div></div><div class="left-qrCode"><!-- 安卓二维码位置 --><div class="qrCode-and">1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/andDemos/yingyan/android-preview.png</div><div>扫码体验</div></div></div><div class="wrap_right"><div class="wrap_right_nav"><div class="wrap_right_nav_l"><div>使用产品</div><div><!-- 安卓使用产品下选项,可有多个 --><!-- 产品1|/index.php?title=test --><div class="documentA">鹰眼地理围栏|index.php?title=android-yingyan/guide/geo-fencing</div></div></div><div class="wrap_right_nav_r">下载源码</div><!-- 安卓源码地址 --><div class="github-url-and">//mapopen-website-wiki.cdn.bcebos.com/demos/andDemos/app-release.apk</div></div><div class="wrap_table"><div class="table_nav"><div class="left-icon"></div><div>核心接口</div></div><div class="table_wrap"><div class="table_wrap_title"><div>类</div><div>接口</div><div>描述</div></div><!-- 表格接口,可有多个 --><div class="table_wrap_con"><div class="table_wrap_w"><div><div class="table-wrap-className">LBSTraceClient</div></div><div><div>createFence(CreateFenceRequest request, OnFenceListener listener)</div></div><div><div>创建围栏</div></div></div><!-- --><div class="table_wrap_w"><div><div class="table-wrap-className">CreateFenceRequest</div></div><div><div>buildServerCircleRequest(int tag, long serviceId, java.lang.String fenceName, java.lang.String monitoredPerson, LatLng center, double radius, int denoise, CoordType coordType)</div></div><div><div>创建服务端圆形围栏请求实例</div></div></div></div></div></div></div></div><div class="pre-nav"><div class="left-icon"></div><div>重点介绍</div></div><div class="pre-wrap"><br/>围栏报警支持推送至鹰眼SDK,统一由OnTraceListener监听器中的onPushCallback()推送回调接口接收。 开发者可在报警回调中触发自身业务,如发送短信至其他监控者、推送至开发者服务端等。<br/><br/>当接收报警的手机断网或网络状态不好时,会导致报警推送失败,鹰眼服务端将在后续的10分钟之内每隔15s推送一次,直至收到成功响应。若10分钟之后仍未成功,将不再推送,但报警记录将存储在鹰眼服务端。为避免因此造成报警漏接收,开发者可定期使用历史报警查询接口同步报警信息。</div><div class="pre-nav"><div class="left-icon"></div><div>核心代码</div></div><div class="pre-wrap">注意:请求和回调是相对应关系。</div><div class="pre-nav"><div>1.发起检索请求</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-and"><pre class="prettyprint prettyprinted pre-and">/** | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | </div> | + | |
− | <div class="demos_wrap"> | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
* 创建圆形服务围栏 | * 创建圆形服务围栏 | ||
*/ | */ | ||
第139行: | 第26行: | ||
trackApp.mClient.createFence(request, fenceListener); | trackApp.mClient.createFence(request, fenceListener); | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>2.检索结果处理</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-and"><pre class="prettyprint prettyprinted pre-and">OnFenceListener fenceListener = new OnFenceListener() { | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
@Override | @Override | ||
public void onCreateFenceCallback(CreateFenceResponse response) { | public void onCreateFenceCallback(CreateFenceResponse response) { | ||
第208行: | 第80行: | ||
} | } | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>3.围栏报警推送</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-and"><pre class="prettyprint prettyprinted pre-and">traceListener = new OnTraceListener() { | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
...... | ...... | ||
/** | /** | ||
第271行: | 第128行: | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div></div><div class="ios-wrap wrap" style="display: none;"><div class="wrap-wp"><div class="wrap_left"><div class="left-video"><div class="img-bg-ios-sh"></div><div class="phone-ios"><div class="video-wrap infor"><div class="video-control"></div><!-- ios视频位置 --><pre>//mapopen-website-wiki.cdn.bcebos.com/demos/ioscodes/yingyan/地理围栏.mp4</pre> | |
− | + | </div><div class="video-icon-ios"><div class="play play-ios"></div><div class="stop stop-ios"></div></div></div><div class="progressWrap-hide-ios"></div><div id="videoControls-ios"><div id="progressWrap-ios"><div id="playProgress-ios"></div></div></div></div><div class="left-qrCode iosqrCode"><!-- ios二维码位置 --><div class="qrCode-ios">1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/ioscodes/yingyan/ios-preview-demo.png</div><div>扫码体验</div></div></div><div class="wrap_right"><div class="wrap_right_nav"><div class="wrap_right_nav_l"><div>使用产品</div><div><div class="documentA">鹰眼地理围栏|index.php?title=ios-yingyan/guide/geo-fencing</div><!-- --></div></div><div class="wrap_right_nav_r">下载源码</div><!-- IOS源码地址 --><div class="github-url-ios">//mapopen-website-wiki.bj.bcebos.com/demos/ioscodes/yingyan/BaiduTraceSDK_v3.1.3_iOS_demo.zip</div></div><div class="wrap_table"><div class="table_nav"><div class="left-icon"></div><div>核心接口</div></div><div class="table_wrap"><div class="table_wrap_title"><div>类</div><div>接口</div><div>描述</div></div><!-- ios表格接口内容,可有多个 --><!-- 表格接口,可有多个 --><div class="table_wrap_con"><div class="table_wrap_w"><div><div class="table-wrap-className">BTKServerCircleFence</div></div><div><div>-(instancetype)initWithCenter:(CLLocationCoordinate2D)center radius:(double)radius coordType:(BTKCoordType)coordType denoiseAccuracy:(NSUInteger)denoiseAccuracy fenceName:(NSString *)fenceName monitoredObject:(NSString*)monitoredObject;</div></div><div><div>创建围栏</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BTKCreateServerFenceRequest</div></div><div><div>-(instancetype)initWithServerCircleFence:(BTKServerCircleFence *)fence serviceID:(NSUInteger)serviceID tag:(NSUInteger)tag;</div></div><div><div>创建服务端圆形围栏请求实例</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BTKFenceAction</div></div><div><div>-(void)createServerFenceWith:(BTKCreateServerFenceRequest *)request delegate:(id <BTKFenceDelegate>)delegate;</div></div><div><div>发起创建请求</div></div></div></div></div></div></div></div><div class="pre-nav"><div class="left-icon"></div><div>重点介绍</div></div><div class="pre-wrap">当服务端围栏被触发之后,会通过长连接将报警信息推送给SDK,SDK会通过 BTKActionDelegate 协议的 -(void)onGetPushMessage:(BTKPushMessage *)message; 方法将报警信息推送给开发者。因此服务端围栏的报警推送要求网络畅通。当接收报警的手机断网或网络状态不好时,会导致报警推送失败,鹰眼服务端将在后续的10分钟之内每隔15s推送一次,直至收到成功响应。若10分钟之后仍未成功,将不再推送,但报警记录将存储在鹰眼服务端。为避免因此造成报警漏接收,开发者可定期使用历史报警查询接口同步报警信息。</div><div class="pre-nav"><div class="left-icon"></div><div>核心代码</div></div><div class="pre-nav"><div>1.发起检索请求</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>Objective-C</div></div><div class="pre-wrap-w pre-wrap-w-ios code_container"><!-- ios示例代码位置 --><pre class="prettyprint prettyprinted pre-ios">BTKServerCircleFence *fence = [[BTKServerCircleFence alloc] initWithCenter:self.circleCenter radius:radius coordType:BTK_COORDTYPE_BD09LL denoiseAccuracy:denoise fenceName:fenceName monitoredObject:monitoredObject]; | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
BTKCreateServerFenceRequest *request = [[BTKCreateServerFenceRequest alloc] initWithServerCircleFence:fence serviceID:serviceID tag:1]; | BTKCreateServerFenceRequest *request = [[BTKCreateServerFenceRequest alloc] initWithServerCircleFence:fence serviceID:serviceID tag:1]; | ||
[[BTKFenceAction sharedInstance] createServerFenceWith:request delegate:self]; | [[BTKFenceAction sharedInstance] createServerFenceWith:request delegate:self]; | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-ios">复制</div><div class="pre-btn-cb-ios">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>2.检索结果处理</div></div><div class="pre-wrap">注意:请求和回调是相对应关系。</div><div class="pre-wrap"><div class="pre-wrap-nav"><div>Objective-C</div></div><div class="pre-wrap-w pre-wrap-w-ios code_container"><!-- ios示例代码位置 --><pre class="prettyprint prettyprinted pre-ios">#pragma mark - BTKFenceDelegate | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
-(void)onCreateServerFence:(NSData *)response { | -(void)onCreateServerFence:(NSData *)response { | ||
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingAllowFragments error:nil]; | NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingAllowFragments error:nil]; | ||
第432行: | 第156行: | ||
} | } | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-ios">复制</div><div class="pre-btn-cb-ios">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>3.围栏报警推送</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>Objective-C</div></div><div class="pre-wrap-w pre-wrap-w-ios code_container"><!-- ios示例代码位置 --><pre class="prettyprint prettyprinted pre-ios">-(void)onGetPushMessage:(BTKPushMessage *)message { | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
NSLog(@"收到推送消息,消息类型: %@", @(message.type)); | NSLog(@"收到推送消息,消息类型: %@", @(message.type)); | ||
if (message.type == 0x03) { | if (message.type == 0x03) { | ||
第459行: | 第168行: | ||
} | } | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-ios">复制</div><div class="pre-btn-cb-ios">深色</div></div><div class="success">复制成功</div></div></div></div></div> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | </div> | + |
2021年2月19日 (五) 10:37的版本
地理围栏
注意
下面的接口介绍创建围栏示例代码以圆形服务围栏为例,多边形围栏、线型围栏 可下载demo 参考
Android
iOS
//mapopen-website-wiki.cdn.bcebos.com/demos/andDemos/yingyan/地理围栏.mp4
1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/andDemos/yingyan/android-preview.png
扫码体验
使用产品
鹰眼地理围栏|index.php?title=android-yingyan/guide/geo-fencing
下载源码
//mapopen-website-wiki.cdn.bcebos.com/demos/andDemos/app-release.apk
核心接口
类
接口
描述
LBSTraceClient
createFence(CreateFenceRequest request, OnFenceListener listener)
创建围栏
CreateFenceRequest
buildServerCircleRequest(int tag, long serviceId, java.lang.String fenceName, java.lang.String monitoredPerson, LatLng center, double radius, int denoise, CoordType coordType)
创建服务端圆形围栏请求实例
重点介绍
围栏报警支持推送至鹰眼SDK,统一由OnTraceListener监听器中的onPushCallback()推送回调接口接收。 开发者可在报警回调中触发自身业务,如发送短信至其他监控者、推送至开发者服务端等。
当接收报警的手机断网或网络状态不好时,会导致报警推送失败,鹰眼服务端将在后续的10分钟之内每隔15s推送一次,直至收到成功响应。若10分钟之后仍未成功,将不再推送,但报警记录将存储在鹰眼服务端。为避免因此造成报警漏接收,开发者可定期使用历史报警查询接口同步报警信息。
核心代码
注意:请求和回调是相对应关系。
1.发起检索请求
JAVA
/** * 创建圆形服务围栏 */ private void createFence() { // 请求标识 int tag = 3; // 轨迹服务ID long serviceId = 0123443l; // 围栏名称 String fenceName = "server_circle"; // 监控对象 "#allentity" 为监控全部entity的特殊字符 String monitoredPerson = "#allentity"; // 围栏圆心 com.baidu.trace.model.LatLng center = new com.baidu.trace.model.LatLng(39.9151190000, 116.4039630000); // 围栏半径(单位 : 米) double radius = 2000; // 去噪精度 int denoise = 200; // 坐标类型 CoordType coordType = CoordType.bd09ll; // 创建服务端圆形围栏请求实例 CreateFenceRequest request = CreateFenceRequest.buildServerCircleRequest(tag, serviceId, fenceName, monitoredPerson, center, radius, denoise, coordType); // 创建围栏 trackApp.mClient.createFence(request, fenceListener);
复制
深色
复制成功
2.检索结果处理
JAVA
OnFenceListener fenceListener = new OnFenceListener() { @Override public void onCreateFenceCallback(CreateFenceResponse response) { // 创建围栏回调接口 } @Override public void onUpdateFenceCallback(UpdateFenceResponse response) { // 更新围栏回调接口 } @Override public void onDeleteFenceCallback(DeleteFenceResponse response) { // 删除围栏回调处理 } @Override public void onFenceListCallback(FenceListResponse response) { // 查询围栏列表回调接口 } @Override public void onMonitoredStatusCallback(MonitoredStatusResponse response) { // 查询监控对象状态回调接口 } @Override public void onMonitoredStatusByLocationCallback(MonitoredStatusByLocationResponse response) { // 查询指定位置监控对象状态回调接口 } @Override public void onHistoryAlarmCallback(HistoryAlarmResponse response) { // 查询围栏历史报警信息回调接口 } @Override public void onAddMonitoredPersonCallback(AddMonitoredPersonResponse response) { // 添加服务端围栏需要监控的对象(轨迹entity) } @Override public void onDeleteMonitoredPersonCallback(DeleteMonitoredPersonResponse response) { // 删除服务端围栏需要监控的对象(轨迹entity) } @Override public void onListMonitoredPersonCallback(ListMonitoredPersonResponse response) { // 查询围栏监控的所有entity } }; }
复制
深色
复制成功
3.围栏报警推送
JAVA
traceListener = new OnTraceListener() { ...... /** * 推送消息回调接口 * * @param messageType 状态码 * @param pushMessage 消息 * * 0x01:配置下发 * 0x02:语音消息 * 0x03:服务端围栏报警消息 * 0x04:本地围栏报警消息 * 0x05~0x40:系统预留 * 0x41~0xFF:开发者自定义 */ @Override public void onPushCallback(byte messageType, PushMessage pushMessage) { if (messageType < 0x03 || messageType > 0x04) { viewUtil.showToast(TracingActivity.this, pushMessage.getMessage()); return; } FenceAlarmPushInfo alarmPushInfo = pushMessage.getFenceAlarmPushInfo(); if (null == alarmPushInfo) { viewUtil.showToast(TracingActivity.this, String.format("onPushCallback, messageType:%d, messageContent:%s ", messageType, pushMessage)); return; } StringBuffer alarmInfo = new StringBuffer(); alarmInfo.append("您于") .append(CommonUtil.getHMS(alarmPushInfo.getCurrentPoint().getLocTime() * 1000)) .append(alarmPushInfo.getMonitoredAction() == MonitoredAction.enter ? "进入" : "离开") .append(messageType == 0x03 ? "云端" : "本地") .append("围栏:").append(alarmPushInfo.getFenceName()); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) { Notification notification = new Notification.Builder(trackApp) .setContentTitle(getResources().getString(R.string.alarm_push_title)) .setContentText(alarmInfo.toString()) .setSmallIcon(R.mipmap.icon_app) .setWhen(System.currentTimeMillis()).build(); notificationManager.notify(notifyId++, notification); } } };
复制
深色
复制成功