12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>location</title>
- <script src="js/axios.min.js"></script>
- <script src="https://web.tianyunperfect.cn/util.js"></script>
- <script type="text/javascript"
- src="https://api.map.baidu.com/api?v=2.0&ak=WMYeXwq7z0VcaiUXTuYTGPZsm8Selmfd"></script>
- </head>
- <body>
- <textarea id="msg" style="width: 100%; font-size: 25px" rows="10"></textarea>
- <h1 id="tip">2秒内发送</h1>
- <script>
- Date.prototype.format = function (fmt) {
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- }
- for (var k in o) {
- if (new RegExp("(" + k + ")").test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- }
- }
- return fmt;
- }
- </script>
- <script>
- let longitude;
- let latitude;
- let status = false;
- function getLocation() {
- // 创建百度地理位置实例,代替 navigator.geolocation
- var geolocation = new BMap.Geolocation();
- geolocation.getCurrentPosition(function (e) {
- if (this.getStatus() == BMAP_STATUS_SUCCESS) {
- // 百度 geolocation 的经纬度属性不同,此处是 point.lat 而不是 coords.latitude
- latitude = e.point.lat;
- longitude = e.point.lng;
- } else {
- }
- });
- }
- getLocation();
- setTimeout(() => {
- if (status === false) {
- sendMsg();
- }
- }, 2000)
- function setTip(str) {
- document.querySelector('#tip').innerHTML = str;
- }
- document.querySelector("#msg").onfocus = function () {
- status = true;
- setTip('点击发送');
- document.querySelector("#tip").onclick = function () {
- sendMsg();
- };
- };
- function sendMsg() {
- axios.post("https://api.tianyunperfect.cn/web_history/location_history", {
- "location_str": "",
- "location_xy": latitude + "," + longitude,
- "msg": document.querySelector("#msg").value,
- "create_time": new Date().format('yyyy-MM-dd hh:mm:ss'),
- "update_time": new Date().format('yyyy-MM-dd hh:mm:ss'),
- "user_id": getQueryString("user_id")
- }).then(res => {
- if (res.data.code === 1) {
- // window.close();
- if (longitude === undefined) {
- setTip("发送成功,但是没有经纬度");
- } else {
- setTip("发送成功!!!!!!");
- }
- }
- });
- }
- </script>
- </body>
- </html>
|