location.html 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>location</title>
  7. <script src="js/axios.min.js"></script>
  8. <script src="https://web.tianyunperfect.cn/util.js"></script>
  9. <script type="text/javascript"
  10. src="https://api.map.baidu.com/api?v=2.0&ak=WMYeXwq7z0VcaiUXTuYTGPZsm8Selmfd"></script>
  11. </head>
  12. <body>
  13. <textarea id="msg" style="width: 100%; font-size: 25px" rows="10"></textarea>
  14. <h1 id="tip">2秒内发送</h1>
  15. <script>
  16. Date.prototype.format = function (fmt) {
  17. var o = {
  18. "M+": this.getMonth() + 1, //月份
  19. "d+": this.getDate(), //日
  20. "h+": this.getHours(), //小时
  21. "m+": this.getMinutes(), //分
  22. "s+": this.getSeconds(), //秒
  23. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  24. "S": this.getMilliseconds() //毫秒
  25. };
  26. if (/(y+)/.test(fmt)) {
  27. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  28. }
  29. for (var k in o) {
  30. if (new RegExp("(" + k + ")").test(fmt)) {
  31. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  32. }
  33. }
  34. return fmt;
  35. }
  36. </script>
  37. <script>
  38. let longitude;
  39. let latitude;
  40. let status = false;
  41. function getLocation() {
  42. // 创建百度地理位置实例,代替 navigator.geolocation
  43. var geolocation = new BMap.Geolocation();
  44. geolocation.getCurrentPosition(function (e) {
  45. if (this.getStatus() == BMAP_STATUS_SUCCESS) {
  46. // 百度 geolocation 的经纬度属性不同,此处是 point.lat 而不是 coords.latitude
  47. latitude = e.point.lat;
  48. longitude = e.point.lng;
  49. } else {
  50. }
  51. });
  52. }
  53. getLocation();
  54. setTimeout(() => {
  55. if (status === false) {
  56. sendMsg();
  57. }
  58. }, 2000)
  59. function setTip(str) {
  60. document.querySelector('#tip').innerHTML = str;
  61. }
  62. document.querySelector("#msg").onfocus = function () {
  63. status = true;
  64. setTip('点击发送');
  65. document.querySelector("#tip").onclick = function () {
  66. sendMsg();
  67. };
  68. };
  69. function sendMsg() {
  70. axios.post("https://api.tianyunperfect.cn/web_history/location_history", {
  71. "location_str": "",
  72. "location_xy": latitude + "," + longitude,
  73. "msg": document.querySelector("#msg").value,
  74. "create_time": new Date().format('yyyy-MM-dd hh:mm:ss'),
  75. "update_time": new Date().format('yyyy-MM-dd hh:mm:ss'),
  76. "user_id": getQueryString("user_id")
  77. }).then(res => {
  78. if (res.data.code === 1) {
  79. // window.close();
  80. if (longitude === undefined) {
  81. setTip("发送成功,但是没有经纬度");
  82. } else {
  83. setTip("发送成功!!!!!!");
  84. }
  85. }
  86. });
  87. }
  88. </script>
  89. </body>
  90. </html>