移动警务考勤打卡组合定位实现
一、業(yè)務(wù)邏輯
本次分享的是移動(dòng)警務(wù)項(xiàng)目考勤模塊的代碼實(shí)現(xiàn),該模塊的主要業(yè)務(wù)邏輯是用戶到達(dá)要考勤的目標(biāo)點(diǎn)-》打開移動(dòng)警務(wù)軟件的考勤模塊-》系統(tǒng)自動(dòng)進(jìn)行組合定位-》定位成功后,選擇打卡方式-》最后提交考勤結(jié)果即可,具體步驟如下:
1、用戶登錄后在首頁選擇考勤管理,進(jìn)入簽到記錄頁面,點(diǎn)擊右上角的+號,進(jìn)入考勤簽到模塊;
?
2、進(jìn)入考勤簽到模塊,若GPS已經(jīng)開啟,則會(huì)在20秒內(nèi)嘗試獲取GPS數(shù)據(jù),如果定位成功,則調(diào)用業(yè)務(wù)平臺的POI查詢接口,獲取當(dāng)前考勤點(diǎn)的名稱,跳轉(zhuǎn)到步驟5;
3、若GPS定位失敗,則會(huì)在10秒內(nèi)進(jìn)行MapABC的網(wǎng)絡(luò)定位,如果定位成功,則調(diào)用業(yè)務(wù)平臺的POI查詢接口,獲取當(dāng)前考勤點(diǎn)的名稱, 跳轉(zhuǎn)到步驟5;
4、若MapABC的網(wǎng)絡(luò)定位,則會(huì)在10秒內(nèi)調(diào)用遼寧基地的SDK進(jìn)行定位,如果定位成功,則調(diào)用業(yè)務(wù)平臺的POI查詢接口,獲取當(dāng)前考勤點(diǎn)的名稱, 跳轉(zhuǎn)到步驟5,否則跳轉(zhuǎn)到步驟7;
5、顯示當(dāng)前的考勤點(diǎn)信息;
6、選擇考勤點(diǎn),進(jìn)行打開,程序跳轉(zhuǎn)到上一頁面面;
7、如果基地的SDK定位仍然失敗,則本次定位失敗!
二、流程圖
三、代碼實(shí)現(xiàn)
1、定義變量,用于保存超時(shí)計(jì)數(shù)和獲得的經(jīng)緯度
local g_retryCount = 20 -- GPS定位超時(shí)計(jì)數(shù) local net_retryCount = 20 -- 網(wǎng)絡(luò)定位超時(shí)計(jì)數(shù) local latitude = 0 -- 當(dāng)前的緯度:字符串類型,小數(shù)點(diǎn)后精確6位 local longitude = 0 -- 當(dāng)前的經(jīng)度:字符串類型,小數(shù)點(diǎn)后精確6位?
2、組合定位的入口函數(shù)
-- @brief 組合定位方式獲取當(dāng)前的經(jīng)緯度 function getCurrentLocation()-- 初始化MapABC定位地址g_address = nil local locInfo = Sprite:findChild(rootSprite, 'kaoqinlocation')Sprite:setProperty(locInfo, 'text', '正在定位......')-- 當(dāng)前無經(jīng)緯度信息,檢查當(dāng)前gps狀態(tài)local result = System:getGPSStatus()if result == -1 thenSprite:setProperty(locInfo, 'text', '當(dāng)前GPS不可用, 嘗試使用網(wǎng)絡(luò)定位...')Log:write('GPS開啟失敗, 嘗試使用網(wǎng)絡(luò)定位...')getLocationByNetwork()elseif result == 0 thenSprite:setProperty(locInfo, 'text', 'GPS未開啟,嘗試使用網(wǎng)絡(luò)定位...')getLocationByNetwork()elseif result == 1 thenSprite:setProperty(locInfo, 'text', 'GPS已經(jīng)開啟,正在使用GPS定位...')Timer:set(222, 1000, 'getLocationByGPS')end end?
3、利用GPS獲取當(dāng)前經(jīng)緯度
-- @brief 利用GPS獲取經(jīng)緯度,需要多次進(jìn)行請求 function getLocationByGPS()-- 獲取當(dāng)前的經(jīng)緯度數(shù)據(jù)local locInfo = Sprite:findChild(rootSprite, 'kaoqinlocation')Sprite:setProperty(locInfo, "text", "GPS正在定位中,剩余"..g_retryCount.."秒")longitude,latitude = System:getGPSData()Log:write(string.format("當(dāng)前經(jīng)緯度: %s, %s", latitude, longitude))-- 對獲得的數(shù)據(jù)進(jìn)行處理if longitude ~= nil and longitude ~= 0 and latitude ~= nil and latitude ~= 0 and g_retryCount > 0 thenLog:write("GPS數(shù)據(jù)有效!")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-- 未超時(shí)需要繼續(xù)請求Log:write("GPS數(shù)據(jù)無效!")g_retryCount = g_retryCount - 1Timer:set(222, 1000, 'getLocationByGPS')else-- 已經(jīng)超時(shí),進(jìn)行網(wǎng)絡(luò)定位System:setGPSStatus(0)g_retryCount = 20Log:write('GPS定位失敗, 嘗試使用網(wǎng)絡(luò)定位...')Sprite:setProperty(locInfo, 'text', 'GPS定位失敗,嘗試使用網(wǎng)絡(luò)定位...')getLocationByNetwork()end end
4、網(wǎng)絡(luò)定位入口函數(shù)
5、高德定位獲取當(dāng)前經(jīng)緯度
?
6、遼寧基地獲取當(dāng)前經(jīng)緯度
-- @brief 遼寧基地網(wǎng)絡(luò)定位獲取當(dāng)前經(jīng)緯度 function getLocationByJD()Log:write("嘗試使用遼寧基地網(wǎng)絡(luò)定位獲取當(dāng)前經(jīng)緯度...")local code = LuaToJavaExec('Clutter','GetLocationByJD', "[]", 1, "GetLocationByJDCallback");Log:write("LuaToJavaExec函數(shù)返回:", code) end -- @brief 遼寧基地網(wǎng)絡(luò)定位回調(diào)函數(shù) function GetLocationByJDCallback(strMsg)Log:write("遼寧基地網(wǎng)絡(luò)定位返回字符串:"..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("解析后的經(jīng)緯度為:"..latitude..", "..longitude)latitude,longitude = formatLocation(latitude, longitude)resetNetworkLocation()poiSearch(latitude, longitude, "0") end
7、格式化經(jīng)緯度函數(shù)
8、POI查詢接口函數(shù)
?
總結(jié)
以上是生活随笔為你收集整理的移动警务考勤打卡组合定位实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iTop4412开发板Android4.
- 下一篇: Python3爬取知网文章