瀏覽代碼

更换天地图服务

xiaohaizhao 1 年之前
父節點
當前提交
e6a868cf4c
共有 3 個文件被更改,包括 51 次插入93 次删除
  1. 9 53
      packageA/clockIn/signIn.js
  2. 10 40
      packageA/publicClue/modules/follow/insert.js
  3. 32 0
      utils/tianditu.js

+ 9 - 53
packageA/clockIn/signIn.js

@@ -1,8 +1,8 @@
 const _Http = getApp().globalData.http;
-/* const QQMapWX = require('../../utils/qqmap-wx-jssdk.min'),
-    qqmapsdk = new QQMapWX({
-        key: 'QF6BZ-4IQC5-SN2IH-QL5BW-U4IJO-R3BY4' // 必填
-    }); */
+
+import { tianditu } from "../../utils/tianditu.js";
+const api = new tianditu();
+
 import {
     formatTime
 } from "../../utils/getTime";
@@ -258,29 +258,14 @@ Page({
                 latitude,
                 longitude
             }) {
-                console.log('bu精确', latitude, longitude)
                 wx.hideLoading();
-                _Http.basic({
-                    "id": "10027201",
-                    "content": {
-                        "lon": longitude,
-                        "lat": latitude
-                    }
-                }).then(res => {
-                    console.log("获取逆解析地址", res)
-                    if (res.msg != '成功') return wx.showToast({
-                        title: res.msg,
-                        icon: "none"
-                    })
-                    if (res.data.msg != 'ok') return wx.showToast({
-                        title: '定位失败,请查看手机是否开启定位服务',
-                        icon: "none"
-                    })
-                    let result = res.data.result;
+                api.getPlace(longitude, latitude).then((place) => {
+                    console.log("获取逆解析地址", place)
+                    let result = place.result;
                     that.setData({
                         content: {
-                            province: result.addressComponent.province,
-                            city: result.addressComponent.city,
+                            province: result.addressComponent.province|| result.addressComponent.city,
+                            city: result.addressComponent.city||result.addressComponent.province,
                             county: result.addressComponent.county,
                             address: result.formatted_address,
                             latitude,
@@ -291,35 +276,6 @@ Page({
                         }
                     })
                 })
-                /*   qqmapsdk.reverseGeocoder({
-                      location: {
-                          latitude,
-                          longitude
-                      },
-                      success(s) {
-                          console.log("逆解析", s)
-                          that.setData({
-                              content: {
-                                  province: s.result.address_component.province,
-                                  city: s.result.address_component.city,
-                                  county: s.result.address_component.district,
-                                  address: s.result.address,
-                                  longitude,
-                                  latitude,
-                                  remarks: "",
-                                  sa_projectid: 0,
-                                  sys_enterpriseid: 0
-                              }
-                          })
-                      },
-                      fail(err) {
-                          console.log(err)
-                          wx.showToast({
-                              title: '定位失败,请查看手机是否开启定位服务',
-                              icon: "none"
-                          })
-                      }
-                  }) */
             },
             fail: function (e) {
                 //这里是获取失败的时候

+ 10 - 40
packageA/publicClue/modules/follow/insert.js

@@ -2,10 +2,11 @@ const _Http = getApp().globalData.http,
     {
         formatTime
     } = require("../../../../utils/getTime");
-/*     QQMapWX = require('../../../../utils/qqmap-wx-jssdk.min'),
-    qqmapsdk = new QQMapWX({
-        key: 'QF6BZ-4IQC5-SN2IH-QL5BW-U4IJO-R3BY4' // 必填
-    }); */
+
+import {
+    tianditu
+} from "../../../../utils/tianditu.js";
+const api = new tianditu();
 Page({
     data: {
         disabled: true,
@@ -80,43 +81,12 @@ Page({
                     latitude,
                     longitude
                 }) {
-                    that.setData({
-                        "content.latitude": latitude,
-                        "content.longitude": longitude
-                    })
-                    /*        qqmapsdk.reverseGeocoder({
-                               location: {
-                                   latitude,
-                                   longitude
-                               },
-                               success(s) {
-                                   console.log("逆解析", s)
-                                   that.setData({
-                                       "content.address": s.result.address,
-                                   })
-                               }
-                           }) */
-
-                    _Http.basic({
-                        "id": "10027201",
-                        "content": {
-                            "lon": longitude,
-                            "lat": latitude
-                        }
-                    }).then(res => {
-                        console.log("获取逆解析地址", res)
-                        if (res.msg != '成功') return wx.showToast({
-                            title: res.msg,
-                            icon: "none"
-                        })
-                        if (res.data.msg != 'ok') return wx.showToast({
-                            title: '定位失败,请查看手机是否开启定位服务',
-                            icon: "none"
-                        })
+                    api.getPlace(longitude, latitude).then((place) => {
+                        console.log("获取逆解析地址", place)
                         that.setData({
-                            content: {
-                                "content.address": res.data.result.formatted_address,
-                            }
+                            "content.address": place.result.formatted_address,
+                            "content.latitude": latitude,
+                            "content.longitude": longitude
                         })
                     })
                 },

+ 32 - 0
utils/tianditu.js

@@ -0,0 +1,32 @@
+/* 文档 http://lbs.tianditu.gov.cn/server/search2.html */
+
+class tianditu {
+    /* 逆解析 */
+    getPlace(lon, lat) {
+        return this.request(`/geocoder?postStr={'lon':${lon},'lat':${lat},'ver':1}&type=geocode`)
+    }
+    /* 地名搜索 */
+    placeNameSearch(data = {}) {
+        return this.request(`/v2/search?postStr=${JSON.stringify(data)}&type=query`)
+    }
+    request(query, method = 'GET') {
+        const tks = ['524ebc3954aaa26259f80ea937a3f569', '8aad97b24c38ed6643207de9da174b98', '47bb2ca36a43839fd7c45e2d762561f8'],
+            url = 'https://api.tianditu.gov.cn' + query + `&tk=${tks[ Math.floor(Math.random() * tks.length)]}`
+        return new Promise((resolve, reject) => {
+            this._request(url, method, resolve)
+        })
+    }
+    _request(url, method, resolve) {
+        wx.request({
+            url,
+            method,
+            success: (res) => {
+                resolve(res.data)
+            }
+        });
+    }
+}
+
+export {
+    tianditu
+}