util_location.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. local lbsLoc = require "lbsLoc"
  2. local util_location = {}
  3. local last_lat, last_lng = 0, 0
  4. local last_time = 0
  5. -- 获取坐标
  6. function util_location.getCoord(callback, type, wifi, timeout)
  7. local is_callback = callback ~= nil
  8. if callback == nil then
  9. callback = function()
  10. end
  11. end
  12. sys.taskInit(
  13. function()
  14. local current_time = os.time()
  15. if not is_callback then
  16. if current_time - last_time < 30 then
  17. log.info("util_location.getCoord", "距离上次定位时间太短", current_time - last_time)
  18. return
  19. end
  20. sys.wait(1000)
  21. end
  22. last_time = current_time
  23. lbsLoc.request(
  24. function(result, lat, lng, addr, time, locType)
  25. log.info("util_location.getCoord", result, lat, lng, locType)
  26. if result == 0 and lat and lng then
  27. last_lat, last_lng = lat, lng
  28. return callback(lat, lng)
  29. end
  30. return callback(last_lat, last_lng)
  31. end,
  32. nil,
  33. timeout,
  34. "v32xEAKsGTIEQxtqgwCldp5aPlcnPs3K",
  35. nil,
  36. nil,
  37. nil,
  38. wifi
  39. )
  40. end
  41. )
  42. return last_lat, last_lng
  43. end
  44. return util_location