123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <!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 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 locationStr = '';
- let status = false;
- // 获取地址位置的名字
- function getLocationStr() {
- var map = new BMap.Map("l-map");
- // 创建地理编码实例, 并配置参数获取乡镇级数据
- var myGeo = new BMap.Geocoder({extensions_town: true});
- // 根据坐标得到地址描述
- myGeo.getLocation(new BMap.Point(longitude, latitude), function (result) {
- if (result) {
- locationStr = result.address;
- } else {
- return "未知";
- }
- });
- }
- // 获取经纬度
- 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;
- getLocationStr();
- } 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": locationStr,
- "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>
|