一、业务逻辑

本次分享的是移动警务项目考勤模块的代码实现,该模块的主要业务逻辑是用户到达要考勤的目标点-》打开移动警务软件的考勤模块-》系统自动进行组合定位-》定位成功后,选择打卡方式-》最后提交考勤结果即可,具体步骤如下:

1、用户登录后在首页选择考勤管理,进入签到记录页面,点击右上角的+号,进入考勤签到模块;

 

2、进入考勤签到模块,若GPS已经开启,则会在20秒内尝试获取GPS数据,如果定位成功,则调用业务平台的POI查询接口,获取当前考勤点的名称,跳转到步骤5;

3、若GPS定位失败,则会在10秒内进行MapABC的网络定位,如果定位成功,则调用业务平台的POI查询接口,获取当前考勤点的名称, 跳转到步骤5;

4、若MapABC的网络定位,则会在10秒内调用辽宁基地的SDK进行定位,如果定位成功,则调用业务平台的POI查询接口,获取当前考勤点的名称, 跳转到步骤5,否则跳转到步骤7;

5、显示当前的考勤点信息;

6、选择考勤点,进行打开,程序跳转到上一页面面;

7、如果基地的SDK定位仍然失败,则本次定位失败!


二、流程图



三、代码实现

1、定义变量,用于保存超时计数和获得的经纬度

local g_retryCount    = 20     -- GPS定位超时计数
local net_retryCount  = 20     -- 网络定位超时计数
local latitude        = 0      -- 当前的纬度:字符串类型,小数点后精确6位
local longitude       = 0      -- 当前的经度:字符串类型,小数点后精确6位

2、组合定位的入口函数

-- @brief 组合定位方式获取当前的经纬度
function getCurrentLocation()-- 初始化MapABC定位地址g_address = nil local locInfo = Sprite:findChild(rootSprite, 'kaoqinlocation')Sprite:setProperty(locInfo, 'text', '正在定位......')-- 当前无经纬度信息,检查当前gps状态local result = System:getGPSStatus()if result == -1 thenSprite:setProperty(locInfo, 'text', '当前GPS不可用, 尝试使用网络定位...')Log:write('GPS开启失败, 尝试使用网络定位...')getLocationByNetwork()elseif result == 0 thenSprite:setProperty(locInfo, 'text', 'GPS未开启,尝试使用网络定位...')getLocationByNetwork()elseif result == 1 thenSprite:setProperty(locInfo, 'text', 'GPS已经开启,正在使用GPS定位...')Timer:set(222, 1000, 'getLocationByGPS')end
end

3、利用GPS获取当前经纬度

-- @brief 利用GPS获取经纬度,需要多次进行请求
function getLocationByGPS()-- 获取当前的经纬度数据local locInfo = Sprite:findChild(rootSprite, 'kaoqinlocation')Sprite:setProperty(locInfo, "text", "GPS正在定位中,剩余"..g_retryCount.."秒")longitude,latitude = System:getGPSData()Log:write(string.format("当前经纬度: %s, %s", latitude, longitude))-- 对获得的数据进行处理if longitude ~= nil and longitude ~= 0 and latitude ~= nil and latitude ~= 0 and g_retryCount > 0 thenLog:write("GPS数据有效!")g_retryCount = 20System:setGPSStatus(0)latitude, longitude = formatLocation(latitude, longitude)poiSearch(latitude, longitude, "0")elseif longitude == 0 and latitude == 0 and g_retryCount > 0 then-- 未超时需要继续请求Log:write("GPS数据无效!")g_retryCount = g_retryCount - 1Timer:set(222, 1000, 'getLocationByGPS')else-- 已经超时,进行网络定位System:setGPSStatus(0)g_retryCount = 20Log:write('GPS定位失败, 尝试使用网络定位...')Sprite:setProperty(locInfo, 'text', 'GPS定位失败,尝试使用网络定位...')getLocationByNetwork()end
end

4、网络定位入口函数

-- @brief 网络定位获取经纬度
function getLocationByNetwork()local locInfo = Sprite:findChild(rootSprite, 'kaoqinlocation')if net_retryCount > 10 thenif net_retryCount == 20 then getLocationByMapABC()end Sprite:setProperty(locInfo, "text", "MapABC网络定位中,剩余"..(net_retryCount - 10).."秒")net_retryCount = net_retryCount - 1elseif net_retryCount > 0 then if net_retryCount == 10 then getLocationByJD()endSprite:setProperty(locInfo, "text", "辽宁基地网络定位中,剩余"..net_retryCount.."秒")net_retryCount = net_retryCount - 1 elseSprite:setProperty(locInfo, "text", "定位失败,请稍候再试!")resetNetworkLocation()returnendTimer:set(333, 1000, 'getLocationByNetwork')
end

5、高德定位获取当前经纬度

-- @brief 高德网络定位获取当前经纬度
function getLocationByMapABC()Log:write("尝试使用高德网络定位获取当前经纬度...")observer = Plugin:getObserver()Map:getCurPosition(observer, 1001)
end
-- @brief 获取接口返回时的反馈处理
function bodyOnPluginEvent(msg, param)if msg == 1001 then  -- MapABC定位返回local postDataString = Param:getString(param, 0)local postData = Json:loadString2Table(postDataString)Log:write('MapABC网络定位结果:', postData)if postData.longitude ~= nil and postData.latitude ~= nil thenresetNetworkLocation()latitude, longitude = formatLocation(postData.latitude, postData.longitude)g_address = postData.descpoiSearch(latitude, longitude, "1")end   

6、辽宁基地获取当前经纬度

-- @brief 辽宁基地网络定位获取当前经纬度
function getLocationByJD()Log:write("尝试使用辽宁基地网络定位获取当前经纬度...")local code = LuaToJavaExec('Clutter','GetLocationByJD', "[]", 1, "GetLocationByJDCallback");Log:write("LuaToJavaExec函数返回:", code)
end
-- @brief 辽宁基地网络定位回调函数
function GetLocationByJDCallback(strMsg)Log:write("辽宁基地网络定位返回字符串:"..strMsg)local startPos = string.find(strMsg, "\"")local endPos = lastIndexof(strMsg, "\"")local locationStr = string.sub(strMsg, startPos + 1, endPos - 1)local locationArray = Split(locationStr, " ")latitude = locationArray[1]longitude = locationArray[2]Log:write("解析后的经纬度为:"..latitude..", "..longitude)latitude,longitude = formatLocation(latitude, longitude)resetNetworkLocation()poiSearch(latitude, longitude, "0")
end

7、格式化经纬度函数

-- @brief 格式化经纬度
function formatLocation(lat, lon)lat = tonumber(lat)lon = tonumber(lon)while lat > 90 do lat = lat / 10end while lon > 180 dolon = lon / 10end lat = string.format("%.6f", lat)lon = string.format("%.6f", lon)Log:write(string.format("格式化后的经纬度为:%s, %s", lat, lon))return lat, lon
end

8、POI查询接口函数

-- @brief 由经纬度进行POI查询
-- localType : 0 - 真实经纬度, 1 - MapABC经纬度
function poiSearch(lat, lon, locateType)Log:write("进行POI查询,latitude:"..lat..", longitude:"..lon..", locateType:"..locateType)local isShifting  = locateTypelocal requestUrl = string.format("http://120.209.131.154:8080/mobileSale/locateUserType/poi?mobile=%s&longtitude=%s&latitude=%s&radius=%s&isShifting=%s&locateType=%s&productCode=%s",Config:get("username"), lon, lat, "1", isShifting, locateType, Config:get("productKey"))Log:write("自定义POI查询接口地址:"..requestUrl)Http:request('pois', requestUrl, 1003, {useCache = false})Loading:show()
end
elseif msg == 1003 then -- 自定义POI查询接口返回Loading:close()local json = Http:jsonDecode('pois')Log:write("自定义POI查询接口返回:", json)if json.success == "true" and json.list ~= nil and getJsonArrayCount(json.list) > 0 theng_addressList = json.list-- 加载地址选择列表local len = getJsonArrayCount(g_addressList)local addrList = Sprite:findChild(rootSprite, "addrList")local addrSelectItem = Sprite:findChild(rootSprite, "addrSelectItem")ListView:loadItem(addrList, addrSelectItem, len, 'loadListItem')ListView:adjust(addrList) -- 显示取消列表按钮local addrListNode = Sprite:findChild(rootSprite, "addrListNode")Sprite:setProperty(addrListNode, "visible", "true")Sprite:setProperty(addrListNode, "enable", "true")elseLog:write("自定义POI查询失败或为空!")if g_address ~= nil then Log:write("使用高德定位返回的地址")local locInfo = Sprite:findChild(rootSprite, 'kaoqinlocation')Sprite:setProperty(locInfo, "text", g_address)isLocateSuccess = trueelseLog:write("调用高德地址反解接口...")observer = Plugin:getObserver()latitude = tonumber(latitude) * 1000000longitude = tonumber(longitude) * 1000000Map:getLocation(observer, 1004, latitude, longitude)end end 

移动警务考勤打卡组合定位实现相关推荐

  1. 同步考勤数据 钉钉_作为学校,我为何选择微校wxiao考勤打卡?

    随着移动互联网的兴起,越来越多的中小学摒弃了传统纸质考勤方式,采用智能考勤. 目前,最常用的智能考勤方式可分为基于非移动端和移动端两种. 其中,基于非移动端的包括人脸识别.指纹识别.虹膜识别考勤方式, ...

  2. 钉钉怎么设置考勤打卡规则

    1.首先在电脑上登陆钉钉后台,然后点击如图所示的钉钉考勤打卡 钉钉后怎么设置考勤打卡规则? 2.比如一个公司生产型企业 互联网部门上班时间是 周一到周五上班时间 8:30-5:30 周六上班 8:30 ...

  3. 钉钉打卡如何破译人脸识别_疫情常态下,如何选择合适的考勤管理系统和考勤打卡工具?...

    "考勤管理"对于任何企业来说都是不可缺少的,而且随着企业管理的不断加强,考勤管理的重要性日益提升."考勤管理"不仅可以维护工作秩序,提高工作效率,而且对于提升企 ...

  4. 仿钉钉考勤统计页面的日历组件,通过日历展示每日考勤打卡情况,支持在日历上打两种不同类型的点,大致适配各种分辨率效果图

    原文链接:uniapp : 仿钉钉考勤统计页面的日历组件,通过日历展示每日考勤打卡情况,支持在日历上打两种不同类型的点,大致适配各种分辨率 - northwest - 博客园 (cnblogs.com ...

  5. python 打卡记录代码_利用Python实现对考勤打卡数据处理的总结

    利用Python实现对考勤打卡数据处理的总结 一.背景交代 二.说明 三. 8种方法 1. 查看文件是否存在 2. 导入excel文件,并把数据保存为dataframe格式 3. 计算程序运行时间 4 ...

  6. 每日统计部门人员考勤打卡情况并汇总通知

    在值班时,HR需要及时了解到部分人员的打卡情况.这个时候,可以通过腾讯云HiFlow来实现自动通知考勤打卡情况. 实现步骤: Step1:我们进入腾讯云HiFlow官网,进入控制台.我们在触发应用选择 ...

  7. 基于高德地图JsAPI进行浏览器精确定位,实现手机端考勤打卡功能

    前言: 由于项目需求需要在项目中实现手机端(基于网页)考勤打卡功能,最初考虑使用H5自身定位功能,但尝试过后,效果很不稳定.然后尝试使用百度地图JsAPI,百度家的稳定倒是很稳定,没想到的是定位位置和 ...

  8. android 日历考勤管理,android studio中使用recyclerview制作个显示考勤打卡的日历来...

    1. 用户在app端选择个日期就能查询这个月的考勤打卡信息,并以日历上标注不同的颜色来显示给用户,当然这个日历是recyclerview做出来的,只是每行显示7个,表示一周的七天. 2. 员工考勤打卡 ...

  9. 已经提了离职,还有一周就走,公司突然把我移出企业微信,没法考勤打卡, 还要继续上班吗?...

    黎明前的黑暗最容易出事,离职前的几天也最容易出幺蛾子,比如下面这位网友的遭遇: 已经提了离职,还有一周就正式离职了,公司突然把我移出企业微信,没法考勤打卡了, 还要继续上班吗?该怎么办? 有人说,自己 ...

最新文章

  1. 【译】Why Decentralized AI Matters Part II: Technological Enablers
  2. lambda中的钩子函数
  3. 【c】【报错解决】incompatible implicit declaration
  4. 工作80:块级元素的间隙问题
  5. Qt + Python + OpenCV图标替换工具 之 Python调用dll(三)
  6. 炒冷饭系列:设计模式 单例模式
  7. Spring事务管理—aop pointcut expression解析
  8. 国内首家!携程周三、周五可在家“躺平”:76%员工主动报名 !网友:我酸了
  9. 算法设计与分析(第2版)屈婉玲 刘田 张立昂 王捍贫编著 第二章课后习题答案
  10. Vue中导出Excel
  11. 谷歌浏览器插件 - 为 Microsoft Bing 搜索引擎首页添加一个【保存背景图片】的按钮(版本 2)
  12. Windows Server 2016 使用域管理员加域之后无法访问指定设备、路径或文件
  13. 压缩指定大小的BitMap
  14. 定义一个html文档的范围用什么标签,定义一个HTML文档的范围用()标签 A.ol B.ul C.pre D.html...
  15. 软盘是什么_什么是软盘?
  16. xshell使用ssh方式登录百度云服务器
  17. 计算机辅助仿真模拟的英文缩写,全国计算机等级考试一级B模拟题.doc
  18. 无限互联--EGOTableViewPullRefresh个人理解代码原理和使用
  19. PMP备考之如何学习PMBOK?
  20. 无法将类型为“Autodesk.Revit.DB.ElementId”的对象强制转换为类型“System.IConvertible

热门文章

  1. 图像二值化分割阈值的算法——OTSU
  2. 51CTO学习笔记--Linux运维故障排查思路与系统调优技巧视频课程(高俊峰)
  3. JetBrains公司软件版本控制
  4. 网络安全温晓飞老师的课12day 笔记
  5. 【PAT A1066】Root of AVL Tree
  6. Elasticsearch面试问题汇总
  7. 响应式设计的未来是什么?
  8. 工业自动化流水线上的机器视觉检测应用 (三):视觉定位
  9. CentOS国内镜像源地址汇总持续更新
  10. 适用于普源 MSO1000Z / DS1000Z / DS1054Z 系列示波器的上位机软件