移动警务考勤打卡组合定位实现
生活随笔
收集整理的這篇文章主要介紹了
移动警务考勤打卡组合定位实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、業務邏輯
本次分享的是移動警務項目考勤模塊的代碼實現,該模塊的主要業務邏輯是用戶到達要考勤的目標點-》打開移動警務軟件的考勤模塊-》系統自動進行組合定位-》定位成功后,選擇打卡方式-》最后提交考勤結果即可,具體步驟如下:
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、網絡定位入口函數
5、高德定位獲取當前經緯度
?
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、格式化經緯度函數
8、POI查詢接口函數
?
總結
以上是生活随笔為你收集整理的移动警务考勤打卡组合定位实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iTop4412开发板Android4.
- 下一篇: Python3爬取知网文章