【实例简介】

【实例截图】

【核心代码】

package com.uestc.indoorlocation;

import java.util.HashMap;

import java.util.LinkedList;

import java.util.List;

import java.util.Map;

import java.util.Queue;

import android.app.Activity;

import android.bluetooth.BluetoothAdapter;

import android.content.Context;

import android.content.Intent;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.os.Bundle;

import android.os.Message;

import android.util.Log;

import android.view.View;

import android.view.WindowManager;

import android.widget.TextView;

import android.widget.Toast;

import com.aprilbrother.aprilbrothersdk.Beacon;

import com.aprilbrother.aprilbrothersdk.BeaconManager;

import com.aprilbrother.aprilbrothersdk.utils.AprilL;

import com.uestc.indoorlocation.algorithm.Location;

import com.uestc.indoorlocation.common.AppActivity;

import com.uestc.indoorlocation.common.BeaconUtils;

import com.uestc.indoorlocation.common.Constant;

import com.uestc.indoorlocation.common.Point;

import com.uestc.indoorlocation.service.IbeaconListenerService;

public class MainActivity extends AppActivity {

/**

* 显示距离

*/

private TextView tv_distance = null;

private static final int REQUEST_ENABLE_BT = 1234;

private static final String TAG = "beacon";

private BeaconManager beaconManager;

//private ArrayList myBeacons;

private Intent scanIntent = null;

WindowManager wm;

volatile int windowWidth;

volatile int windowHeight;

double scaleX;

double scaleY;

private IndoorPositionView mapView;

private volatile double currentLocationX = (float) 0.0;

private volatile double currentLocationY = (float) 0.0;

/**

* rssi值的queue,针对不同的MAC地址

*/

private volatile Map> rssiMapQueue;

/**

* 计算后的结果值,根据这个值来定位

*/

private volatile Map rssiAvgMap;

/**

* 处理交互信息

* handlerResult函数处理信息类型

* 类型MSG_FRESH_BEACON:得到扫描结果

*

*/

@Override

protected void handleResult(Message msg) {

switch (msg.what) {

//处理beacon位置更新信息

case Constant.MSG_FRESH_BEACON:

//Log.v("beacon", "recved msg: " msg.obj);

if (msg == null) break;

Point position = position(msg);

if (position != null) {

position = getRealPosition(position);

double x = position.getPointX();

double y = position.getPointY();

currentLocationX = x > 0 ? x : 0;

currentLocationY = y > 0 ? y : 0;

mapView.invalidate(); //更新地图坐标点

BeaconUtils.printLogInfo(Constant.LOG_BEACON, "after position ==== x: "

currentLocationX " y: " currentLocationY);

}

break;

}

}

/**

* 处理信号

* @param msg

*/

private void processMsg(Message msg) {

/**

* 将beacon区分开,即key为mac地址,value为相关的Beacon列表

*/

Map> diffBeacons =

BeaconUtils.diffBeacons((List)msg.obj);

/**

* 在Beacon里将rssi值提取出来

*/

Map> rssisAfterFilter = BeaconUtils.beaconFilter(diffBeacons);

/**

* 遍历滤波后的结果值

*/

//Log.v(TAG, "processMsg: " rssisAfterFilter);

for (Map.Entry> entry : rssisAfterFilter.entrySet()) {

Queue queue = rssiMapQueue.get(entry.getKey());

/**

* 初始化时,队列为空,同样结果列表也会为空

*/

if (queue == null || queue.size() == 0) {

BeaconUtils.printLogInfoWithoutOtherMsg("print", "queue is null");

queue = new LinkedList();

rssiMapQueue.put(entry.getKey(), queue);

queue.addAll(entry.getValue());

/**

* 如果队列未满时,则需将队列填满

*/

} else if (queue.size() < Constant.QUEUE_MAX_SIZE) {

BeaconUtils.printLogInfoWithoutOtherMsg("print", "queue not full");

List l = entry.getValue();

int length = l.size();

int i = 0;

while (queue.size() < Constant.QUEUE_MAX_SIZE && i < length-1) {

queue.add(l.get(i ));

}

/**

* 此时,队列已满,则去除队列头部,同时尾部增加一个滤波后的均值

*/

} else {

List list = entry.getValue();

int head = queue.poll();

queue.offer(BeaconUtils.avgOfList(list));

}

//结果取为queue中的均值

rssiAvgMap.put(entry.getKey(), BeaconUtils.avgOfQueue(queue));

}

BeaconUtils.printLogInfo(Constant.LOG_PRINT, "rssiAvgMap: " rssiAvgMap.toString());

BeaconUtils.printLogInfo(Constant.LOG_PRINT, "rssiMapQueue: " rssiMapQueue.toString());

}

/**

* 处理信息,但没有其它的处理,仅取得平均值,即不再有个滑动队列

* @param msg

*/

private void processMsgWithoutOtherAlgorithm(Message msg) {

/**

* 将beacon区分开,即key为mac地址,value为相关的Beacon列表

*/

Map> diffBeacons =

BeaconUtils.diffBeacons((List)msg.obj);

/**

* 在Beacon里将rssi值提取出来

*/

Map> rssisAfterFilter = BeaconUtils.beaconFilter(diffBeacons);

for (Map.Entry> entry : rssisAfterFilter.entrySet()) {

int avg = BeaconUtils.avgOfList(entry.getValue());

rssiAvgMap.put(entry.getKey(), avg);

}

}

/**

* 定位

* @return

*/

public Point position(Message msg) {

//信号处理

processMsg(msg);

//Log.v(TAG, "position(): " rssiAvgMap);

return Location.getInstance().position(rssiAvgMap);

}

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//requestWindowFeature(Window.FEATURE_NO_TITLE);

mapView = new IndoorPositionView(this);

mapView.setBackgroundResource(R.drawable.map_bg);

setContentView(mapView);

init();

}

@SuppressWarnings("deprecation")

private void init(){

wm = this.getWindowManager();

windowWidth = wm.getDefaultDisplay().getWidth();

windowHeight = wm.getDefaultDisplay().getHeight();

//比例

scaleX = windowWidth / 1040.0;

scaleY = windowHeight / 1150.0;

//new Thread(new MessageProcessor()).start(); //启动消息转接线程

scanIntent = new Intent(this, IbeaconListenerService.class);//绑定service

tv_distance = (TextView)findViewById(R.id.distance);

AprilL.enableDebugLogging(true);

beaconManager = new BeaconManager(getApplicationContext());

rssiMapQueue = new HashMap>();

rssiAvgMap = new HashMap();

}

/**

* 坐标转换

* @param point

* @return

*/

private Point getRealPosition(Point point) {

Log.v("scale", "scale x: " scaleX " y: " scaleY);

return new Point(point.getPointX() * scaleX, point.getPointY() * scaleY);

}

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == REQUEST_ENABLE_BT) {

if (resultCode == Activity.RESULT_OK) {

} else {

Toast.makeText(this, "Bluetooth not enabled", Toast.LENGTH_LONG)

.show();

}

}

super.onActivityResult(requestCode, resultCode, data);

}

@Override

protected void onStart() {

super.onStart();

startService(scanIntent);

/**

* 蓝牙开闭判断

*/

if (!beaconManager.hasBluetooth()) {

Log.v(TAG, "request bluttooth");

Toast.makeText(this, "Device does not have Bluetooth Low Energy",

Toast.LENGTH_LONG).show();

return;

}

if (!beaconManager.isBluetoothEnabled()) {

Log.v(TAG, "on start bluetooth");

Intent enableBtIntent = new Intent(

BluetoothAdapter.ACTION_REQUEST_ENABLE);

startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

}

}

@Override

protected void onDestroy() {

super.onDestroy();

}

@Override

protected void onStop() {

stopService(scanIntent);

super.onStop();

}

/**

* 显示的简单图片地图,

* 作为内部类主要是好处理坐标信息

* @author vincent

*

*/

class IndoorPositionView extends View{

private Paint paint = new Paint();

public IndoorPositionView(Context context) {

super(context);

setFocusable(true);

}

public void onDraw(Canvas canvas) {

paint.setStyle(Paint.Style.FILL);

paint.setAntiAlias(true);

paint.setColor(Color.RED);

canvas.drawCircle((float)currentLocationX, (float)currentLocationY, 10, paint);

}

}

}

java室内定位 源码_android 室内定位 源码下载(蓝牙定位)相关推荐

  1. 蓝牙定位技术使室内定位更加精准--高精度定位--新导智能

    谈到蓝牙,很多人榜首知道无疑是已经在消费者身边普及的无线耳机.可穿戴设备.智能家居间的连接办法.蓝牙已经成为了几乎一切设备的标配,应用的设备小到手机.平板电脑,再到互联设备.再到轿车,并在智能楼宇.智 ...

  2. 室内精准定位市场大洗牌,蓝牙定位是否会成为主流?

    蓝牙定位是一种支持设备短距离通信(一般10m内)的无线电技术,能在包括移动电话.PDA.无线耳机.笔记本电脑.相关外设等众多设备之间进行无线信息交换. 5G.北斗.GPS等高精度定位技术的高速发展,给 ...

  3. Android 停车地图及停车导航,停车场蓝牙定位导航方案

    停车场蓝牙定位导航方案基于微能信息开发的蓝牙定位系统方案,与固有停车场管理系统深度结合,为顾客在智能手机终端提供全方面的停车场空余车位导航.记录停车位.反向寻车.查找路线.查找公共设施等服务. 停车场 ...

  4. MINI型 UWB 室内定位开发模块电路图及PCB和源码开源

    MINI型 UWB 室内定位开发模块电路图及PCB和源码开源 UWB Node 是一款体积小的 UWB 室内定位开发模块,采用 STM32F411CE 芯片以及 DWM1000 模块,板上有九轴惯性传 ...

  5. android+ble室内定位,基于BLE的室内定位系统的设计与实现

    摘要: 由于卫星信号到达室内后衰减严重,使得全球卫星定位系统无法满足室内定位的需求.而如今随着社会的发展与城市化进程的推进,人们一天中80%的时间都是在室内消耗的,再加上基于位置服务(Location ...

  6. 微信小程序-3D地图场景+定位导航-法院3D室内导航系统-为群众提供诉讼全流程导航服务

    随着互联网信息的快速发展,我国的信息化水平也得到了全面的提升.尤其近几年在疫情的影响下,微信的小程序应用已经渗入生活的方方面面,无论是日常出行的健康码还是线上商城的购物,小程序以其轻便.响应速度快.不 ...

  7. android 9.0室内定位方案,Android GPS室内定位问题的解决方法(location为null)

    为什么室内没有location呢? 因为我们开发的时候几乎肯定都是在室内的,这个时候卫星你是搜索不到的,所以必然是定位不了的,所以系统如何将位置信息通知给你的程序.所以要从根本上解决这个问题,就要解决 ...

  8. zigbee定位_基于RFID室内定位技术的解决方案,能满足高精度室内定位吗?

    跟着物联网的研讨和无线传感网络技能迅速发展,ZigBee技能作为一种新式的低成本.低功耗.低速率短间隔的无线传感网络技能,它是根据IEEE802.15.4规范开发的无线协议.IEEE802.15.4担 ...

  9. rssi室内定位算法原理_室内定位方案常用的4种定位算法

    目前常见的室内定位技术有超宽带UWB室内定位技术,蓝牙室内定位技术,RFID(无线射频识别)定位,超声波定位,Wi-Fi定位等.室内定位依赖于定位算法,定位算法决定了室内定位的模式.室内定位种类虽然比 ...

最新文章

  1. R包reshape2,轻松实现长、宽数据表格转换
  2. Git 命令行的使用
  3. Matlab与C++混合编程
  4. url模糊匹配优化_企业必备的网站SEO优化解决方案
  5. Plist文件和字典转模型
  6. 支持串行隔离级别_从0到1理解数据库事务(上):并发问题与隔离级别
  7. Time.deltaTime 含义和应用
  8. 配置管理-CMMI的五个等级
  9. rtt面向对象oopc——3.对官方IO设备模型框架图的补充绘图
  10. 【EduCoder实训答案】JSP入门
  11. 按夏普计算机技巧,股票投资策略:怎样用夏普比率Sharpe Ratio寻找强势股
  12. 先锋建筑设计师——庞嵚作品
  13. python魂斗罗源码_经典儿时游戏魂斗罗源代码
  14. 得意不张狂失败不气妥
  15. STK12已出,STK 12 新特性介绍
  16. Word设置多套页码奇偶跨章节页眉【毕业论文格式记录】
  17. 分布式学习(3)etcd@2@HTTP API v2
  18. Nginx域名配置详细介绍
  19. postman报错500 Internal Server Error
  20. qml 中的function怎么加类型_皮炎有哪些类型?生活中皮炎要怎么预防?得了皮炎要注意哪些问题...

热门文章

  1. 根据给定的x和y的list值,如何利用matplotlib画曲线图?
  2. java工厂模式三种详解(部分转载)
  3. java之简易的文件加密器的实现
  4. java 运行批处理文件_如何从Java应用程序运行批处理文件?
  5. download.js 实现txt,js文件等浏览器下载 而不是打开
  6. 春晚架构&Ylmf OSChrom OS
  7. PdfReader 2:this.readPdf() -4 PdfName
  8. php登录 无漏洞,AKCMS 6.0 /akcms/login.php 登录绕过漏洞
  9. stm32 神舟3号 开发板 usb DFU 实现
  10. e900V21e刷机固件及教程(电信创维)