注:订阅上车提醒后会根据订阅参数中的索引站点, 通过RealtimeBusNotifyListener返回实时公交是否到站信息, SDK内部未做提醒之后取消提醒的逻辑,最近的车辆驶过之后会继续查询下一辆公交车辆的信息并发出提醒, 如需取消订阅上车提醒需调用unregisterGetOnBusSubscription接口。
RealtimeBusNotifyListener realtimeBusNotifyListener = new RealtimeBusNotifyListener() {@Overridepublic void getOnBusNotify(RealTimeBusStatus info) {// 上车提醒状态回调}@Overridepublic void getOffBusNotify(RealTimeBusStatus info) {// 下车提醒状态回调}@Overridepublic void errorMessage(SearchResult.ERRORNO subscribeResult) {// 订阅结果错误信息返回}};
Subscriber subscriber = new Subscriber();subscriber.setLocation(latLng); // 设置当前位置boolean res = RealTimeBusManager.getInstance().registerGetOnBusSubscription(subscriber, // 订阅者位置getOnBusIndex, // 站台索引busLineUid, // 线路UID131, // 城市IDrealtimeBusNotifyListener); // 监听数据回调if(res) {Toast.makeText(RTBusLineActivity.this, "开启上车提醒成功", Toast.LENGTH_SHORT).show();} else {Toast.makeText(RTBusLineActivity.this, "开启上车提醒失败,请检测相关订阅参数并重新设置",Toast.LENGTH_SHORT).show();}
注:下车提醒在分别提醒还有一站和还剩一分钟,车辆到站之后SDK内部会取消下车提醒的订阅
Subscriber subscriber = new Subscriber();subscriber.setLocation(latLng); // 设置当前位置boolean res = RealTimeBusManager.getInstance().registerGetOffBusSubscription(subscriber,getOffBusIndex, // 下车站台索引busLineUid, // 线路Uid131, // 城市idrealtimeBusNotifyListener);if(res) {Toast.makeText(RTBusLineActivity.this, "开启下车提醒成功", Toast.LENGTH_SHORT).show();} else{Toast.makeText(RTBusLineActivity.this, "开启下车提醒失败,请检查参数并重新开启",Toast.LENGTH_SHORT).show();}
RealTimeBusManager.getInstance().unregisterGetOnBusSubscription();
RealTimeBusManager.getInstance().unregisterGetOffBusSubscription();
上一篇
下一篇
本篇文章对您是否有帮助?