日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

移动警务考勤打卡组合定位实现

發(fā)布時(shí)間:2024/1/1 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 移动警务考勤打卡组合定位实现 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、業(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ù)

-- @brief 網(wǎng)絡(luò)定位獲取經(jīng)緯度 function getLocationByNetwork()local locInfo = Sprite:findChild(rootSprite, 'kaoqinlocation')if net_retryCount > 10 thenif net_retryCount == 20 then getLocationByMapABC()end Sprite:setProperty(locInfo, "text", "MapABC網(wǎng)絡(luò)定位中,剩余"..(net_retryCount - 10).."秒")net_retryCount = net_retryCount - 1elseif net_retryCount > 0 then if net_retryCount == 10 then getLocationByJD()endSprite:setProperty(locInfo, "text", "遼寧基地網(wǎng)絡(luò)定位中,剩余"..net_retryCount.."秒")net_retryCount = net_retryCount - 1 elseSprite:setProperty(locInfo, "text", "定位失敗,請稍候再試!")resetNetworkLocation()returnendTimer:set(333, 1000, 'getLocationByNetwork') end


5、高德定位獲取當(dāng)前經(jīng)緯度

-- @brief 高德網(wǎng)絡(luò)定位獲取當(dāng)前經(jīng)緯度 function getLocationByMapABC()Log:write("嘗試使用高德網(wǎng)絡(luò)定位獲取當(dāng)前經(jīng)緯度...")observer = Plugin:getObserver()Map:getCurPosition(observer, 1001) end -- @brief 獲取接口返回時(shí)的反饋處理 function bodyOnPluginEvent(msg, param)if msg == 1001 then -- MapABC定位返回local postDataString = Param:getString(param, 0)local postData = Json:loadString2Table(postDataString)Log:write('MapABC網(wǎng)絡(luò)定位結(jié)果:', 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、遼寧基地獲取當(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ù)

-- @brief 格式化經(jīng)緯度 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("格式化后的經(jīng)緯度為:%s, %s", lat, lon))return lat, lon end


8、POI查詢接口函數(shù)

-- @brief 由經(jīng)緯度進(jìn)行POI查詢 -- localType : 0 - 真實(shí)經(jīng)緯度, 1 - MapABC經(jīng)緯度 function poiSearch(lat, lon, locateType)Log:write("進(jìn)行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查詢失敗或?yàn)榭?#xff01;")if g_address ~= nil then Log:write("使用高德定位返回的地址")local locInfo = Sprite:findChild(rootSprite, 'kaoqinlocation')Sprite:setProperty(locInfo, "text", g_address)isLocateSuccess = trueelseLog:write("調(diào)用高德地址反解接口...")observer = Plugin:getObserver()latitude = tonumber(latitude) * 1000000longitude = tonumber(longitude) * 1000000Map:getLocation(observer, 1004, latitude, longitude)end end



?

總結(jié)

以上是生活随笔為你收集整理的移动警务考勤打卡组合定位实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。