Commit 49a45f56e9ce171893e08e86edc426e5b16832cb
1 parent
d0f9ccb8
地址解析为经纬度
Showing
9 changed files
with
47 additions
and
771 deletions
pages/work/case/clean.vue
| @@ -133,7 +133,7 @@ export default { | @@ -133,7 +133,7 @@ export default { | ||
| 133 | isLoading: false, | 133 | isLoading: false, |
| 134 | serverURL: uploadURL, | 134 | serverURL: uploadURL, |
| 135 | currentIndex: 0, | 135 | currentIndex: 0, |
| 136 | - tabList: ['开始处理照片', '进行中照片', '结束照片', '人员照片', '使用材料照片'], | 136 | + tabList: ['开始', '进行', '结束', '人员', '材料'], |
| 137 | staffList: [], | 137 | staffList: [], |
| 138 | selectShow: false | 138 | selectShow: false |
| 139 | } | 139 | } |
pages/work/case/manure.vue
| @@ -131,7 +131,7 @@ export default { | @@ -131,7 +131,7 @@ export default { | ||
| 131 | isLoading: false, | 131 | isLoading: false, |
| 132 | serverURL: uploadURL, | 132 | serverURL: uploadURL, |
| 133 | currentIndex: 0, | 133 | currentIndex: 0, |
| 134 | - tabList: ['开始处理照片', '进行中照片', '结束照片', '人员照片', '使用材料照片'], | 134 | + tabList: ['开始', '进行', '结束', '人员', '材料'], |
| 135 | staffList: [], | 135 | staffList: [], |
| 136 | selectShow: false | 136 | selectShow: false |
| 137 | } | 137 | } |
pages/work/case/replant.vue
| @@ -126,7 +126,7 @@ export default { | @@ -126,7 +126,7 @@ export default { | ||
| 126 | isLoading: false, | 126 | isLoading: false, |
| 127 | serverURL: uploadURL, | 127 | serverURL: uploadURL, |
| 128 | currentIndex: 0, | 128 | currentIndex: 0, |
| 129 | - tabList: ['开始处理照片', '进行中照片', '结束照片', '人员照片', '使用材料照片'], | 129 | + tabList: ['开始', '进行', '结束', '人员', '材料'], |
| 130 | staffList: [], | 130 | staffList: [], |
| 131 | selectShow: false | 131 | selectShow: false |
| 132 | } | 132 | } |
pages/work/case/water.vue
| @@ -164,7 +164,7 @@ | @@ -164,7 +164,7 @@ | ||
| 164 | isLoading: false, | 164 | isLoading: false, |
| 165 | serverURL: uploadURL, | 165 | serverURL: uploadURL, |
| 166 | currentIndex: 0, | 166 | currentIndex: 0, |
| 167 | - tabList: ['开始处理照片', '进行中照片', '结束照片', '人员照片', '使用材料照片'], | 167 | + tabList: ['开始', '进行', '结束', '人员', '材料'], |
| 168 | selectType: 1, | 168 | selectType: 1, |
| 169 | selectList: [], | 169 | selectList: [], |
| 170 | selectShow: false | 170 | selectShow: false |
pages/work/case/weed.vue
| @@ -119,7 +119,7 @@ export default { | @@ -119,7 +119,7 @@ export default { | ||
| 119 | isLoading: false, | 119 | isLoading: false, |
| 120 | serverURL: uploadURL, | 120 | serverURL: uploadURL, |
| 121 | currentIndex: 0, | 121 | currentIndex: 0, |
| 122 | - tabList: ['开始处理照片', '进行中照片', '结束照片', '人员照片', '使用材料照片'], | 122 | + tabList: ['开始', '进行', '结束', '人员', '材料'], |
| 123 | staffList: [], | 123 | staffList: [], |
| 124 | selectShow: false | 124 | selectShow: false |
| 125 | } | 125 | } |
pages/work/daily/reporting.vue
| @@ -124,7 +124,6 @@ export default { | @@ -124,7 +124,6 @@ export default { | ||
| 124 | this.hotlinenumber = options.hotlinenumber | 124 | this.hotlinenumber = options.hotlinenumber |
| 125 | if(this.hotlinenumber){ | 125 | if(this.hotlinenumber){ |
| 126 | 126 | ||
| 127 | - | ||
| 128 | // 1. 获取 eventChannel 实例 | 127 | // 1. 获取 eventChannel 实例 |
| 129 | const eventChannel = this.getOpenerEventChannel(); | 128 | const eventChannel = this.getOpenerEventChannel(); |
| 130 | 129 | ||
| @@ -201,6 +200,43 @@ export default { | @@ -201,6 +200,43 @@ export default { | ||
| 201 | this.formData.problemSourceId = 2 | 200 | this.formData.problemSourceId = 2 |
| 202 | this.formData.thirdWorkOrderNo = largeData.hotlinenumber | 201 | this.formData.thirdWorkOrderNo = largeData.hotlinenumber |
| 203 | 202 | ||
| 203 | + const key = 'f8693f334fa04f3749677f4b4f13b286'; | ||
| 204 | + // 高德地理编码API | ||
| 205 | + uni.request({ | ||
| 206 | + url: 'https://restapi.amap.com/v3/geocode/geo', | ||
| 207 | + method: 'GET', | ||
| 208 | + data: { | ||
| 209 | + address: this.formData.lonLatAddress, // 要解析的地址,如"北京市朝阳区光华路" | ||
| 210 | + key: key, // 你的高德Key | ||
| 211 | + city: '北京' // 可选,指定城市可提高解析精度 | ||
| 212 | + }, | ||
| 213 | + success: (res) => { | ||
| 214 | + const result = res.data; | ||
| 215 | + if (result.status === '1' && result.count > 0) { | ||
| 216 | + // 解析成功,获取经纬度 | ||
| 217 | + const geocodes = result.geocodes[0]; | ||
| 218 | + const location = geocodes.location.split(','); // 格式为"经度,纬度" | ||
| 219 | + const longitude = location[0]; | ||
| 220 | + const latitude = location[1]; | ||
| 221 | + this.formData.lon = longitude | ||
| 222 | + this.formData.lat = latitude | ||
| 223 | + | ||
| 224 | + console.log('解析成功:', { | ||
| 225 | + address: geocodes.formatted_address, | ||
| 226 | + longitude: longitude, | ||
| 227 | + latitude: latitude | ||
| 228 | + }); | ||
| 229 | + } else { | ||
| 230 | + this.formData.lon = '116.364966' | ||
| 231 | + this.formData.lat = '39.920401' | ||
| 232 | + console.log('解析失败:', result.info || '未找到匹配地址'); | ||
| 233 | + } | ||
| 234 | + }, | ||
| 235 | + fail: (err) => { | ||
| 236 | + console.log('请求失败:', err); | ||
| 237 | + } | ||
| 238 | + }); | ||
| 239 | + | ||
| 204 | // this.formData.imgs = largeData.casepic | 240 | // this.formData.imgs = largeData.casepic |
| 205 | if(largeData.casepic){ | 241 | if(largeData.casepic){ |
| 206 | let picData = largeData.casepic.replace(OSSURL, "") | 242 | let picData = largeData.casepic.replace(OSSURL, "") |
pages/work/daily/workOrder.vue
| @@ -32,11 +32,7 @@ | @@ -32,11 +32,7 @@ | ||
| 32 | </template> | 32 | </template> |
| 33 | 33 | ||
| 34 | <script> | 34 | <script> |
| 35 | -// const QQMapWX = require('./utils/qqmap-wx-jssdk.js') | ||
| 36 | -// 实例化API核心类 | ||
| 37 | -// let qqMap = new QQMapWX({ | ||
| 38 | -// key: 'H77BZ-RVOKL-UOXPH-EXMFC-5XSGT-YDFIC' | ||
| 39 | -// }); | 35 | + |
| 40 | import { hotlinecaseList } from '@/api/work' | 36 | import { hotlinecaseList } from '@/api/work' |
| 41 | import { useCounterStore } from '@/stores/counter' | 37 | import { useCounterStore } from '@/stores/counter' |
| 42 | export default { | 38 | export default { |
| @@ -47,30 +43,12 @@ export default { | @@ -47,30 +43,12 @@ export default { | ||
| 47 | } | 43 | } |
| 48 | }, | 44 | }, |
| 49 | onLoad() { | 45 | onLoad() { |
| 50 | - // this.qqmapsdk = new QQMapWX({ | ||
| 51 | - // key: 'H77BZ-RVOKL-UOXPH-EXMFC-5XSGT-YDFIC' | ||
| 52 | - // }) | 46 | + |
| 53 | }, | 47 | }, |
| 54 | onShow(){ | 48 | onShow(){ |
| 55 | if (this.$refs.paging) { | 49 | if (this.$refs.paging) { |
| 56 | this.$refs.paging.refresh() // 重置到第一页并触发query事件 | 50 | this.$refs.paging.refresh() // 重置到第一页并触发query事件 |
| 57 | } | 51 | } |
| 58 | - const address = '北京市海淀区中关村大街' | ||
| 59 | - | ||
| 60 | - // this.qqmapsdk.geocoder({ | ||
| 61 | - // address: address, | ||
| 62 | - // success: (res) => { | ||
| 63 | - // if (res.status === 0) { | ||
| 64 | - // this.location = res.result.location | ||
| 65 | - // console.log('解析成功:', res.result.location) | ||
| 66 | - // } else { | ||
| 67 | - // console.error('解析失败:', res.message) | ||
| 68 | - // } | ||
| 69 | - // }, | ||
| 70 | - // fail: (err) => { | ||
| 71 | - // console.error('接口调用失败:', err) | ||
| 72 | - // } | ||
| 73 | - // }) | ||
| 74 | 52 | ||
| 75 | }, | 53 | }, |
| 76 | methods: { | 54 | methods: { |
utils/qqmap-wx-jssdk.js deleted
| 1 | -/** | ||
| 2 | - * 微信小程序JavaScriptSDK | ||
| 3 | - * | ||
| 4 | - * @version 1.1 | ||
| 5 | - * @date 2019-01-20 | ||
| 6 | - */ | ||
| 7 | - | ||
| 8 | -var ERROR_CONF = { | ||
| 9 | - KEY_ERR: 311, | ||
| 10 | - KEY_ERR_MSG: 'key格式错误', | ||
| 11 | - PARAM_ERR: 310, | ||
| 12 | - PARAM_ERR_MSG: '请求参数信息有误', | ||
| 13 | - SYSTEM_ERR: 600, | ||
| 14 | - SYSTEM_ERR_MSG: '系统错误', | ||
| 15 | - WX_ERR_CODE: 1000, | ||
| 16 | - WX_OK_CODE: 200 | ||
| 17 | -}; | ||
| 18 | -var BASE_URL = 'https://apis.map.qq.com/ws/'; | ||
| 19 | -var URL_SEARCH = BASE_URL + 'place/v1/search'; | ||
| 20 | -var URL_SUGGESTION = BASE_URL + 'place/v1/suggestion'; | ||
| 21 | -var URL_GET_GEOCODER = BASE_URL + 'geocoder/v1/'; | ||
| 22 | -var URL_CITY_LIST = BASE_URL + 'district/v1/list'; | ||
| 23 | -var URL_AREA_LIST = BASE_URL + 'district/v1/getchildren'; | ||
| 24 | -var URL_DISTANCE = BASE_URL + 'distance/v1/'; | ||
| 25 | -var EARTH_RADIUS = 6378136.49; | ||
| 26 | -var Utils = { | ||
| 27 | - /** | ||
| 28 | - * 得到终点query字符串 | ||
| 29 | - * @param {Array|String} 检索数据 | ||
| 30 | - */ | ||
| 31 | - location2query(data) { | ||
| 32 | - if (typeof data == 'string') { | ||
| 33 | - return data; | ||
| 34 | - } | ||
| 35 | - var query = ''; | ||
| 36 | - for (var i = 0; i < data.length; i++) { | ||
| 37 | - var d = data[i]; | ||
| 38 | - if (!!query) { | ||
| 39 | - query += ';'; | ||
| 40 | - } | ||
| 41 | - if (d.location) { | ||
| 42 | - query = query + d.location.lat + ',' + d.location.lng; | ||
| 43 | - } | ||
| 44 | - if (d.latitude && d.longitude) { | ||
| 45 | - query = query + d.latitude + ',' + d.longitude; | ||
| 46 | - } | ||
| 47 | - } | ||
| 48 | - return query; | ||
| 49 | - }, | ||
| 50 | - | ||
| 51 | - /** | ||
| 52 | - * 计算角度 | ||
| 53 | - */ | ||
| 54 | - rad(d) { | ||
| 55 | - return d * Math.PI / 180.0; | ||
| 56 | - }, | ||
| 57 | - /** | ||
| 58 | - * 处理终点location数组 | ||
| 59 | - * @return 返回终点数组 | ||
| 60 | - */ | ||
| 61 | - getEndLocation(location){ | ||
| 62 | - var to = location.split(';'); | ||
| 63 | - var endLocation = []; | ||
| 64 | - for (var i = 0; i < to.length; i++) { | ||
| 65 | - endLocation.push({ | ||
| 66 | - lat: parseFloat(to[i].split(',')[0]), | ||
| 67 | - lng: parseFloat(to[i].split(',')[1]) | ||
| 68 | - }) | ||
| 69 | - } | ||
| 70 | - return endLocation; | ||
| 71 | - }, | ||
| 72 | - | ||
| 73 | - /** | ||
| 74 | - * 计算两点间直线距离 | ||
| 75 | - * @param a 表示纬度差 | ||
| 76 | - * @param b 表示经度差 | ||
| 77 | - * @return 返回的是距离,单位m | ||
| 78 | - */ | ||
| 79 | - getDistance(latFrom, lngFrom, latTo, lngTo) { | ||
| 80 | - var radLatFrom = this.rad(latFrom); | ||
| 81 | - var radLatTo = this.rad(latTo); | ||
| 82 | - var a = radLatFrom - radLatTo; | ||
| 83 | - var b = this.rad(lngFrom) - this.rad(lngTo); | ||
| 84 | - var distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLatFrom) * Math.cos(radLatTo) * Math.pow(Math.sin(b / 2), 2))); | ||
| 85 | - distance = distance * EARTH_RADIUS; | ||
| 86 | - distance = Math.round(distance * 10000) / 10000; | ||
| 87 | - return parseFloat(distance.toFixed(0)); | ||
| 88 | - }, | ||
| 89 | - /** | ||
| 90 | - * 使用微信接口进行定位 | ||
| 91 | - */ | ||
| 92 | - getWXLocation(success, fail, complete) { | ||
| 93 | - wx.getLocation({ | ||
| 94 | - type: 'gcj02', | ||
| 95 | - success: success, | ||
| 96 | - fail: fail, | ||
| 97 | - complete: complete | ||
| 98 | - }); | ||
| 99 | - }, | ||
| 100 | - | ||
| 101 | - /** | ||
| 102 | - * 获取location参数 | ||
| 103 | - */ | ||
| 104 | - getLocationParam(location) { | ||
| 105 | - if (typeof location == 'string') { | ||
| 106 | - var locationArr = location.split(','); | ||
| 107 | - if (locationArr.length === 2) { | ||
| 108 | - location = { | ||
| 109 | - latitude: location.split(',')[0], | ||
| 110 | - longitude: location.split(',')[1] | ||
| 111 | - }; | ||
| 112 | - } else { | ||
| 113 | - location = {}; | ||
| 114 | - } | ||
| 115 | - } | ||
| 116 | - return location; | ||
| 117 | - }, | ||
| 118 | - | ||
| 119 | - /** | ||
| 120 | - * 回调函数默认处理 | ||
| 121 | - */ | ||
| 122 | - polyfillParam(param) { | ||
| 123 | - param.success = param.success || function () { }; | ||
| 124 | - param.fail = param.fail || function () { }; | ||
| 125 | - param.complete = param.complete || function () { }; | ||
| 126 | - }, | ||
| 127 | - | ||
| 128 | - /** | ||
| 129 | - * 验证param对应的key值是否为空 | ||
| 130 | - * | ||
| 131 | - * @param {Object} param 接口参数 | ||
| 132 | - * @param {String} key 对应参数的key | ||
| 133 | - */ | ||
| 134 | - checkParamKeyEmpty(param, key) { | ||
| 135 | - if (!param[key]) { | ||
| 136 | - var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + key +'参数格式有误'); | ||
| 137 | - param.fail(errconf); | ||
| 138 | - param.complete(errconf); | ||
| 139 | - return true; | ||
| 140 | - } | ||
| 141 | - return false; | ||
| 142 | - }, | ||
| 143 | - | ||
| 144 | - /** | ||
| 145 | - * 验证参数中是否存在检索词keyword | ||
| 146 | - * | ||
| 147 | - * @param {Object} param 接口参数 | ||
| 148 | - */ | ||
| 149 | - checkKeyword(param){ | ||
| 150 | - return !this.checkParamKeyEmpty(param, 'keyword'); | ||
| 151 | - }, | ||
| 152 | - | ||
| 153 | - /** | ||
| 154 | - * 验证location值 | ||
| 155 | - * | ||
| 156 | - * @param {Object} param 接口参数 | ||
| 157 | - */ | ||
| 158 | - checkLocation(param) { | ||
| 159 | - var location = this.getLocationParam(param.location); | ||
| 160 | - if (!location || !location.latitude || !location.longitude) { | ||
| 161 | - var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + ' location参数格式有误'); | ||
| 162 | - param.fail(errconf); | ||
| 163 | - param.complete(errconf); | ||
| 164 | - return false; | ||
| 165 | - } | ||
| 166 | - return true; | ||
| 167 | - }, | ||
| 168 | - | ||
| 169 | - /** | ||
| 170 | - * 构造错误数据结构 | ||
| 171 | - * @param {Number} errCode 错误码 | ||
| 172 | - * @param {Number} errMsg 错误描述 | ||
| 173 | - */ | ||
| 174 | - buildErrorConfig(errCode, errMsg) { | ||
| 175 | - return { | ||
| 176 | - status: errCode, | ||
| 177 | - message: errMsg | ||
| 178 | - }; | ||
| 179 | - }, | ||
| 180 | - | ||
| 181 | - /** | ||
| 182 | - * | ||
| 183 | - * 数据处理函数 | ||
| 184 | - * 根据传入参数不同处理不同数据 | ||
| 185 | - * @param {String} feature 功能名称 | ||
| 186 | - * search 地点搜索 | ||
| 187 | - * suggest关键词提示 | ||
| 188 | - * reverseGeocoder逆地址解析 | ||
| 189 | - * geocoder地址解析 | ||
| 190 | - * getCityList获取城市列表:父集 | ||
| 191 | - * getDistrictByCityId获取区县列表:子集 | ||
| 192 | - * calculateDistance距离计算 | ||
| 193 | - * @param {Object} param 接口参数 | ||
| 194 | - * @param {Object} data 数据 | ||
| 195 | - */ | ||
| 196 | - handleData(param,data,feature){ | ||
| 197 | - if (feature === 'search') { | ||
| 198 | - var searchResult = data.data; | ||
| 199 | - var searchSimplify = []; | ||
| 200 | - for (var i = 0; i < searchResult.length; i++) { | ||
| 201 | - searchSimplify.push({ | ||
| 202 | - id: searchResult[i].id || null, | ||
| 203 | - title: searchResult[i].title || null, | ||
| 204 | - latitude: searchResult[i].location && searchResult[i].location.lat || null, | ||
| 205 | - longitude: searchResult[i].location && searchResult[i].location.lng || null, | ||
| 206 | - address: searchResult[i].address || null, | ||
| 207 | - category: searchResult[i].category || null, | ||
| 208 | - tel: searchResult[i].tel || null, | ||
| 209 | - adcode: searchResult[i].ad_info && searchResult[i].ad_info.adcode || null, | ||
| 210 | - city: searchResult[i].ad_info && searchResult[i].ad_info.city || null, | ||
| 211 | - district: searchResult[i].ad_info && searchResult[i].ad_info.district || null, | ||
| 212 | - province: searchResult[i].ad_info && searchResult[i].ad_info.province || null | ||
| 213 | - }) | ||
| 214 | - } | ||
| 215 | - param.success(data, { | ||
| 216 | - searchResult: searchResult, | ||
| 217 | - searchSimplify: searchSimplify | ||
| 218 | - }) | ||
| 219 | - } else if (feature === 'suggest') { | ||
| 220 | - var suggestResult = data.data; | ||
| 221 | - var suggestSimplify = []; | ||
| 222 | - for (var i = 0; i < suggestResult.length; i++) { | ||
| 223 | - suggestSimplify.push({ | ||
| 224 | - adcode: suggestResult[i].adcode || null, | ||
| 225 | - address: suggestResult[i].address || null, | ||
| 226 | - category: suggestResult[i].category || null, | ||
| 227 | - city: suggestResult[i].city || null, | ||
| 228 | - district: suggestResult[i].district || null, | ||
| 229 | - id: suggestResult[i].id || null, | ||
| 230 | - latitude: suggestResult[i].location && suggestResult[i].location.lat || null, | ||
| 231 | - longitude: suggestResult[i].location && suggestResult[i].location.lng || null, | ||
| 232 | - province: suggestResult[i].province || null, | ||
| 233 | - title: suggestResult[i].title || null, | ||
| 234 | - type: suggestResult[i].type || null | ||
| 235 | - }) | ||
| 236 | - } | ||
| 237 | - param.success(data, { | ||
| 238 | - suggestResult: suggestResult, | ||
| 239 | - suggestSimplify: suggestSimplify | ||
| 240 | - }) | ||
| 241 | - } else if (feature === 'reverseGeocoder') { | ||
| 242 | - var reverseGeocoderResult = data.result; | ||
| 243 | - var reverseGeocoderSimplify = { | ||
| 244 | - address: reverseGeocoderResult.address || null, | ||
| 245 | - latitude: reverseGeocoderResult.location && reverseGeocoderResult.location.lat || null, | ||
| 246 | - longitude: reverseGeocoderResult.location && reverseGeocoderResult.location.lng || null, | ||
| 247 | - adcode: reverseGeocoderResult.ad_info && reverseGeocoderResult.ad_info.adcode || null, | ||
| 248 | - city: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.city || null, | ||
| 249 | - district: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.district || null, | ||
| 250 | - nation: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.nation || null, | ||
| 251 | - province: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.province || null, | ||
| 252 | - street: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.street || null, | ||
| 253 | - street_number: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.street_number || null, | ||
| 254 | - recommend: reverseGeocoderResult.formatted_addresses && reverseGeocoderResult.formatted_addresses.recommend || null, | ||
| 255 | - rough: reverseGeocoderResult.formatted_addresses && reverseGeocoderResult.formatted_addresses.rough || null | ||
| 256 | - }; | ||
| 257 | - if (reverseGeocoderResult.pois) {//判断是否返回周边poi | ||
| 258 | - var pois = reverseGeocoderResult.pois; | ||
| 259 | - var poisSimplify = []; | ||
| 260 | - for (var i = 0;i < pois.length;i++) { | ||
| 261 | - poisSimplify.push({ | ||
| 262 | - id: pois[i].id || null, | ||
| 263 | - title: pois[i].title || null, | ||
| 264 | - latitude: pois[i].location && pois[i].location.lat || null, | ||
| 265 | - longitude: pois[i].location && pois[i].location.lng || null, | ||
| 266 | - address: pois[i].address || null, | ||
| 267 | - category: pois[i].category || null, | ||
| 268 | - adcode: pois[i].ad_info && pois[i].ad_info.adcode || null, | ||
| 269 | - city: pois[i].ad_info && pois[i].ad_info.city || null, | ||
| 270 | - district: pois[i].ad_info && pois[i].ad_info.district || null, | ||
| 271 | - province: pois[i].ad_info && pois[i].ad_info.province || null | ||
| 272 | - }) | ||
| 273 | - } | ||
| 274 | - param.success(data,{ | ||
| 275 | - reverseGeocoderResult: reverseGeocoderResult, | ||
| 276 | - reverseGeocoderSimplify: reverseGeocoderSimplify, | ||
| 277 | - pois: pois, | ||
| 278 | - poisSimplify: poisSimplify | ||
| 279 | - }) | ||
| 280 | - } else { | ||
| 281 | - param.success(data, { | ||
| 282 | - reverseGeocoderResult: reverseGeocoderResult, | ||
| 283 | - reverseGeocoderSimplify: reverseGeocoderSimplify | ||
| 284 | - }) | ||
| 285 | - } | ||
| 286 | - } else if (feature === 'geocoder') { | ||
| 287 | - var geocoderResult = data.result; | ||
| 288 | - var geocoderSimplify = { | ||
| 289 | - title: geocoderResult.title || null, | ||
| 290 | - latitude: geocoderResult.location && geocoderResult.location.lat || null, | ||
| 291 | - longitude: geocoderResult.location && geocoderResult.location.lng || null, | ||
| 292 | - adcode: geocoderResult.ad_info && geocoderResult.ad_info.adcode || null, | ||
| 293 | - province: geocoderResult.address_components && geocoderResult.address_components.province || null, | ||
| 294 | - city: geocoderResult.address_components && geocoderResult.address_components.city || null, | ||
| 295 | - district: geocoderResult.address_components && geocoderResult.address_components.district || null, | ||
| 296 | - street: geocoderResult.address_components && geocoderResult.address_components.street || null, | ||
| 297 | - street_number: geocoderResult.address_components && geocoderResult.address_components.street_number || null, | ||
| 298 | - level: geocoderResult.level || null | ||
| 299 | - }; | ||
| 300 | - param.success(data,{ | ||
| 301 | - geocoderResult: geocoderResult, | ||
| 302 | - geocoderSimplify: geocoderSimplify | ||
| 303 | - }); | ||
| 304 | - } else if (feature === 'getCityList') { | ||
| 305 | - var provinceResult = data.result[0]; | ||
| 306 | - var cityResult = data.result[1]; | ||
| 307 | - var districtResult = data.result[2]; | ||
| 308 | - param.success(data,{ | ||
| 309 | - provinceResult: provinceResult, | ||
| 310 | - cityResult: cityResult, | ||
| 311 | - districtResult: districtResult | ||
| 312 | - }); | ||
| 313 | - } else if (feature === 'getDistrictByCityId') { | ||
| 314 | - var districtByCity = data.result[0]; | ||
| 315 | - param.success(data, districtByCity); | ||
| 316 | - } else if (feature === 'calculateDistance') { | ||
| 317 | - var calculateDistanceResult = data.result.elements; | ||
| 318 | - var distance = []; | ||
| 319 | - for (var i = 0; i < calculateDistanceResult.length; i++){ | ||
| 320 | - distance.push(calculateDistanceResult[i].distance); | ||
| 321 | - } | ||
| 322 | - param.success(data, { | ||
| 323 | - calculateDistanceResult: calculateDistanceResult, | ||
| 324 | - distance: distance | ||
| 325 | - }); | ||
| 326 | - } else { | ||
| 327 | - param.success(data); | ||
| 328 | - } | ||
| 329 | - }, | ||
| 330 | - | ||
| 331 | - /** | ||
| 332 | - * 构造微信请求参数,公共属性处理 | ||
| 333 | - * | ||
| 334 | - * @param {Object} param 接口参数 | ||
| 335 | - * @param {Object} param 配置项 | ||
| 336 | - * @param {String} feature 方法名 | ||
| 337 | - */ | ||
| 338 | - buildWxRequestConfig(param, options, feature) { | ||
| 339 | - var that = this; | ||
| 340 | - options.header = { "content-type": "application/json" }; | ||
| 341 | - options.method = 'GET'; | ||
| 342 | - options.success = function (res) { | ||
| 343 | - var data = res.data; | ||
| 344 | - if (data.status === 0) { | ||
| 345 | - that.handleData(param, data, feature); | ||
| 346 | - } else { | ||
| 347 | - param.fail(data); | ||
| 348 | - } | ||
| 349 | - }; | ||
| 350 | - options.fail = function (res) { | ||
| 351 | - res.statusCode = ERROR_CONF.WX_ERR_CODE; | ||
| 352 | - param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | ||
| 353 | - }; | ||
| 354 | - options.complete = function (res) { | ||
| 355 | - var statusCode = +res.statusCode; | ||
| 356 | - switch(statusCode) { | ||
| 357 | - case ERROR_CONF.WX_ERR_CODE: { | ||
| 358 | - param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | ||
| 359 | - break; | ||
| 360 | - } | ||
| 361 | - case ERROR_CONF.WX_OK_CODE: { | ||
| 362 | - var data = res.data; | ||
| 363 | - if (data.status === 0) { | ||
| 364 | - param.complete(data); | ||
| 365 | - } else { | ||
| 366 | - param.complete(that.buildErrorConfig(data.status, data.message)); | ||
| 367 | - } | ||
| 368 | - break; | ||
| 369 | - } | ||
| 370 | - default:{ | ||
| 371 | - param.complete(that.buildErrorConfig(ERROR_CONF.SYSTEM_ERR, ERROR_CONF.SYSTEM_ERR_MSG)); | ||
| 372 | - } | ||
| 373 | - | ||
| 374 | - } | ||
| 375 | - }; | ||
| 376 | - return options; | ||
| 377 | - }, | ||
| 378 | - | ||
| 379 | - /** | ||
| 380 | - * 处理用户参数是否传入坐标进行不同的处理 | ||
| 381 | - */ | ||
| 382 | - locationProcess(param, locationsuccess, locationfail, locationcomplete) { | ||
| 383 | - var that = this; | ||
| 384 | - locationfail = locationfail || function (res) { | ||
| 385 | - res.statusCode = ERROR_CONF.WX_ERR_CODE; | ||
| 386 | - param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | ||
| 387 | - }; | ||
| 388 | - locationcomplete = locationcomplete || function (res) { | ||
| 389 | - if (res.statusCode == ERROR_CONF.WX_ERR_CODE) { | ||
| 390 | - param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | ||
| 391 | - } | ||
| 392 | - }; | ||
| 393 | - if (!param.location) { | ||
| 394 | - that.getWXLocation(locationsuccess, locationfail, locationcomplete); | ||
| 395 | - } else if (that.checkLocation(param)) { | ||
| 396 | - var location = Utils.getLocationParam(param.location); | ||
| 397 | - locationsuccess(location); | ||
| 398 | - } | ||
| 399 | - } | ||
| 400 | -}; | ||
| 401 | - | ||
| 402 | - | ||
| 403 | -class QQMapWX { | ||
| 404 | - | ||
| 405 | - /** | ||
| 406 | - * 构造函数 | ||
| 407 | - * | ||
| 408 | - * @param {Object} options 接口参数,key 为必选参数 | ||
| 409 | - */ | ||
| 410 | - constructor(options) { | ||
| 411 | - if (!options.key) { | ||
| 412 | - throw Error('key值不能为空'); | ||
| 413 | - } | ||
| 414 | - this.key = options.key; | ||
| 415 | - }; | ||
| 416 | - | ||
| 417 | - /** | ||
| 418 | - * POI周边检索 | ||
| 419 | - * | ||
| 420 | - * @param {Object} options 接口参数对象 | ||
| 421 | - * | ||
| 422 | - * 参数对象结构可以参考 | ||
| 423 | - * @see http://lbs.qq.com/webservice_v1/guide-search.html | ||
| 424 | - */ | ||
| 425 | - search(options) { | ||
| 426 | - var that = this; | ||
| 427 | - options = options || {}; | ||
| 428 | - | ||
| 429 | - Utils.polyfillParam(options); | ||
| 430 | - | ||
| 431 | - if (!Utils.checkKeyword(options)) { | ||
| 432 | - return; | ||
| 433 | - } | ||
| 434 | - | ||
| 435 | - var requestParam = { | ||
| 436 | - keyword: options.keyword, | ||
| 437 | - orderby: options.orderby || '_distance', | ||
| 438 | - page_size: options.page_size || 10, | ||
| 439 | - page_index: options.page_index || 1, | ||
| 440 | - output: 'json', | ||
| 441 | - key: that.key | ||
| 442 | - }; | ||
| 443 | - | ||
| 444 | - if (options.address_format) { | ||
| 445 | - requestParam.address_format = options.address_format; | ||
| 446 | - } | ||
| 447 | - | ||
| 448 | - if (options.filter) { | ||
| 449 | - requestParam.filter = options.filter; | ||
| 450 | - } | ||
| 451 | - | ||
| 452 | - var distance = options.distance || "1000"; | ||
| 453 | - var auto_extend = options.auto_extend || 1; | ||
| 454 | - var region = null; | ||
| 455 | - var rectangle = null; | ||
| 456 | - | ||
| 457 | - //判断城市限定参数 | ||
| 458 | - if (options.region) { | ||
| 459 | - region = options.region; | ||
| 460 | - } | ||
| 461 | - | ||
| 462 | - //矩形限定坐标(暂时只支持字符串格式) | ||
| 463 | - if (options.rectangle) { | ||
| 464 | - rectangle = options.rectangle; | ||
| 465 | - } | ||
| 466 | - | ||
| 467 | - var locationsuccess = function (result) { | ||
| 468 | - if (region && !rectangle) { | ||
| 469 | - //城市限定参数拼接 | ||
| 470 | - requestParam.boundary = "region(" + region + "," + auto_extend + "," + result.latitude + "," + result.longitude + ")"; | ||
| 471 | - } else if (rectangle && !region) { | ||
| 472 | - //矩形搜索 | ||
| 473 | - requestParam.boundary = "rectangle(" + rectangle + ")"; | ||
| 474 | - } else { | ||
| 475 | - requestParam.boundary = "nearby(" + result.latitude + "," + result.longitude + "," + distance + "," + auto_extend + ")"; | ||
| 476 | - } | ||
| 477 | - wx.request(Utils.buildWxRequestConfig(options, { | ||
| 478 | - url: URL_SEARCH, | ||
| 479 | - data: requestParam | ||
| 480 | - }, 'search')); | ||
| 481 | - }; | ||
| 482 | - Utils.locationProcess(options, locationsuccess); | ||
| 483 | - }; | ||
| 484 | - | ||
| 485 | - /** | ||
| 486 | - * sug模糊检索 | ||
| 487 | - * | ||
| 488 | - * @param {Object} options 接口参数对象 | ||
| 489 | - * | ||
| 490 | - * 参数对象结构可以参考 | ||
| 491 | - * http://lbs.qq.com/webservice_v1/guide-suggestion.html | ||
| 492 | - */ | ||
| 493 | - getSuggestion(options) { | ||
| 494 | - var that = this; | ||
| 495 | - options = options || {}; | ||
| 496 | - Utils.polyfillParam(options); | ||
| 497 | - | ||
| 498 | - if (!Utils.checkKeyword(options)) { | ||
| 499 | - return; | ||
| 500 | - } | ||
| 501 | - | ||
| 502 | - var requestParam = { | ||
| 503 | - keyword: options.keyword, | ||
| 504 | - region: options.region || '全国', | ||
| 505 | - region_fix: options.region_fix || 0, | ||
| 506 | - policy: options.policy || 0, | ||
| 507 | - page_size: options.page_size || 10,//控制显示条数 | ||
| 508 | - page_index: options.page_index || 1,//控制页数 | ||
| 509 | - get_subpois : options.get_subpois || 0,//返回子地点 | ||
| 510 | - output: 'json', | ||
| 511 | - key: that.key | ||
| 512 | - }; | ||
| 513 | - //长地址 | ||
| 514 | - if (options.address_format) { | ||
| 515 | - requestParam.address_format = options.address_format; | ||
| 516 | - } | ||
| 517 | - //过滤 | ||
| 518 | - if (options.filter) { | ||
| 519 | - requestParam.filter = options.filter; | ||
| 520 | - } | ||
| 521 | - //排序 | ||
| 522 | - if (options.location) { | ||
| 523 | - var locationsuccess = function (result) { | ||
| 524 | - requestParam.location = result.latitude + ',' + result.longitude; | ||
| 525 | - wx.request(Utils.buildWxRequestConfig(options, { | ||
| 526 | - url: URL_SUGGESTION, | ||
| 527 | - data: requestParam | ||
| 528 | - }, "suggest")); | ||
| 529 | - }; | ||
| 530 | - Utils.locationProcess(options, locationsuccess); | ||
| 531 | - } else { | ||
| 532 | - wx.request(Utils.buildWxRequestConfig(options, { | ||
| 533 | - url: URL_SUGGESTION, | ||
| 534 | - data: requestParam | ||
| 535 | - }, "suggest")); | ||
| 536 | - } | ||
| 537 | - }; | ||
| 538 | - | ||
| 539 | - /** | ||
| 540 | - * 逆地址解析 | ||
| 541 | - * | ||
| 542 | - * @param {Object} options 接口参数对象 | ||
| 543 | - * | ||
| 544 | - * 请求参数结构可以参考 | ||
| 545 | - * http://lbs.qq.com/webservice_v1/guide-gcoder.html | ||
| 546 | - */ | ||
| 547 | - reverseGeocoder(options) { | ||
| 548 | - var that = this; | ||
| 549 | - options = options || {}; | ||
| 550 | - Utils.polyfillParam(options); | ||
| 551 | - var requestParam = { | ||
| 552 | - coord_type: options.coord_type || 5, | ||
| 553 | - get_poi: options.get_poi || 0, | ||
| 554 | - output: 'json', | ||
| 555 | - key: that.key | ||
| 556 | - }; | ||
| 557 | - if (options.poi_options) { | ||
| 558 | - requestParam.poi_options = options.poi_options | ||
| 559 | - } | ||
| 560 | - | ||
| 561 | - var locationsuccess = function (result) { | ||
| 562 | - requestParam.location = result.latitude + ',' + result.longitude; | ||
| 563 | - wx.request(Utils.buildWxRequestConfig(options, { | ||
| 564 | - url: URL_GET_GEOCODER, | ||
| 565 | - data: requestParam | ||
| 566 | - }, 'reverseGeocoder')); | ||
| 567 | - }; | ||
| 568 | - Utils.locationProcess(options, locationsuccess); | ||
| 569 | - }; | ||
| 570 | - | ||
| 571 | - /** | ||
| 572 | - * 地址解析 | ||
| 573 | - * | ||
| 574 | - * @param {Object} options 接口参数对象 | ||
| 575 | - * | ||
| 576 | - * 请求参数结构可以参考 | ||
| 577 | - * http://lbs.qq.com/webservice_v1/guide-geocoder.html | ||
| 578 | - */ | ||
| 579 | - geocoder(options) { | ||
| 580 | - var that = this; | ||
| 581 | - options = options || {}; | ||
| 582 | - Utils.polyfillParam(options); | ||
| 583 | - | ||
| 584 | - if (Utils.checkParamKeyEmpty(options, 'address')) { | ||
| 585 | - return; | ||
| 586 | - } | ||
| 587 | - | ||
| 588 | - var requestParam = { | ||
| 589 | - address: options.address, | ||
| 590 | - output: 'json', | ||
| 591 | - key: that.key | ||
| 592 | - }; | ||
| 593 | - | ||
| 594 | - //城市限定 | ||
| 595 | - if (options.region) { | ||
| 596 | - requestParam.region = options.region; | ||
| 597 | - } | ||
| 598 | - | ||
| 599 | - wx.request(Utils.buildWxRequestConfig(options, { | ||
| 600 | - url: URL_GET_GEOCODER, | ||
| 601 | - data: requestParam | ||
| 602 | - },'geocoder')); | ||
| 603 | - }; | ||
| 604 | - | ||
| 605 | - | ||
| 606 | - /** | ||
| 607 | - * 获取城市列表 | ||
| 608 | - * | ||
| 609 | - * @param {Object} options 接口参数对象 | ||
| 610 | - * | ||
| 611 | - * 请求参数结构可以参考 | ||
| 612 | - * http://lbs.qq.com/webservice_v1/guide-region.html | ||
| 613 | - */ | ||
| 614 | - getCityList(options) { | ||
| 615 | - var that = this; | ||
| 616 | - options = options || {}; | ||
| 617 | - Utils.polyfillParam(options); | ||
| 618 | - var requestParam = { | ||
| 619 | - output: 'json', | ||
| 620 | - key: that.key | ||
| 621 | - }; | ||
| 622 | - | ||
| 623 | - wx.request(Utils.buildWxRequestConfig(options, { | ||
| 624 | - url: URL_CITY_LIST, | ||
| 625 | - data: requestParam | ||
| 626 | - },'getCityList')); | ||
| 627 | - }; | ||
| 628 | - | ||
| 629 | - /** | ||
| 630 | - * 获取对应城市ID的区县列表 | ||
| 631 | - * | ||
| 632 | - * @param {Object} options 接口参数对象 | ||
| 633 | - * | ||
| 634 | - * 请求参数结构可以参考 | ||
| 635 | - * http://lbs.qq.com/webservice_v1/guide-region.html | ||
| 636 | - */ | ||
| 637 | - getDistrictByCityId(options) { | ||
| 638 | - var that = this; | ||
| 639 | - options = options || {}; | ||
| 640 | - Utils.polyfillParam(options); | ||
| 641 | - | ||
| 642 | - if (Utils.checkParamKeyEmpty(options, 'id')) { | ||
| 643 | - return; | ||
| 644 | - } | ||
| 645 | - | ||
| 646 | - var requestParam = { | ||
| 647 | - id: options.id || '', | ||
| 648 | - output: 'json', | ||
| 649 | - key: that.key | ||
| 650 | - }; | ||
| 651 | - | ||
| 652 | - wx.request(Utils.buildWxRequestConfig(options, { | ||
| 653 | - url: URL_AREA_LIST, | ||
| 654 | - data: requestParam | ||
| 655 | - },'getDistrictByCityId')); | ||
| 656 | - }; | ||
| 657 | - | ||
| 658 | - /** | ||
| 659 | - * 用于单起点到多终点的路线距离(非直线距离)计算: | ||
| 660 | - * 支持两种距离计算方式:步行和驾车。 | ||
| 661 | - * 起点到终点最大限制直线距离10公里。 | ||
| 662 | - * | ||
| 663 | - * 新增直线距离计算。 | ||
| 664 | - * | ||
| 665 | - * @param {Object} options 接口参数对象 | ||
| 666 | - * | ||
| 667 | - * 请求参数结构可以参考 | ||
| 668 | - * http://lbs.qq.com/webservice_v1/guide-distance.html | ||
| 669 | - */ | ||
| 670 | - calculateDistance(options) { | ||
| 671 | - var that = this; | ||
| 672 | - options = options || {}; | ||
| 673 | - Utils.polyfillParam(options); | ||
| 674 | - | ||
| 675 | - if (Utils.checkParamKeyEmpty(options, 'to')) { | ||
| 676 | - return; | ||
| 677 | - } | ||
| 678 | - | ||
| 679 | - var requestParam = { | ||
| 680 | - mode: options.mode || 'walking', | ||
| 681 | - to: Utils.location2query(options.to), | ||
| 682 | - output: 'json', | ||
| 683 | - key: that.key | ||
| 684 | - }; | ||
| 685 | - | ||
| 686 | - if (options.from) { | ||
| 687 | - options.location = options.from; | ||
| 688 | - } | ||
| 689 | - | ||
| 690 | - //计算直线距离 | ||
| 691 | - if(requestParam.mode == 'straight'){ | ||
| 692 | - var locationsuccess = function (result) { | ||
| 693 | - var locationTo = Utils.getEndLocation(requestParam.to);//处理终点坐标 | ||
| 694 | - var data = { | ||
| 695 | - message:"query ok", | ||
| 696 | - result:{ | ||
| 697 | - elements:[] | ||
| 698 | - }, | ||
| 699 | - status:0 | ||
| 700 | - }; | ||
| 701 | - for (var i = 0; i < locationTo.length; i++) { | ||
| 702 | - data.result.elements.push({//将坐标存入 | ||
| 703 | - distance: Utils.getDistance(result.latitude, result.longitude, locationTo[i].lat, locationTo[i].lng), | ||
| 704 | - duration:0, | ||
| 705 | - from:{ | ||
| 706 | - lat: result.latitude, | ||
| 707 | - lng:result.longitude | ||
| 708 | - }, | ||
| 709 | - to:{ | ||
| 710 | - lat: locationTo[i].lat, | ||
| 711 | - lng: locationTo[i].lng | ||
| 712 | - } | ||
| 713 | - }); | ||
| 714 | - } | ||
| 715 | - var calculateResult = data.result.elements; | ||
| 716 | - var distanceResult = []; | ||
| 717 | - for (var i = 0; i < calculateResult.length; i++) { | ||
| 718 | - distanceResult.push(calculateResult[i].distance); | ||
| 719 | - } | ||
| 720 | - return options.success(data,{ | ||
| 721 | - calculateResult: calculateResult, | ||
| 722 | - distanceResult: distanceResult | ||
| 723 | - }); | ||
| 724 | - }; | ||
| 725 | - | ||
| 726 | - Utils.locationProcess(options, locationsuccess); | ||
| 727 | - } else { | ||
| 728 | - var locationsuccess = function (result) { | ||
| 729 | - requestParam.from = result.latitude + ',' + result.longitude; | ||
| 730 | - wx.request(Utils.buildWxRequestConfig(options, { | ||
| 731 | - url: URL_DISTANCE, | ||
| 732 | - data: requestParam | ||
| 733 | - },'calculateDistance')); | ||
| 734 | - }; | ||
| 735 | - | ||
| 736 | - Utils.locationProcess(options, locationsuccess); | ||
| 737 | - } | ||
| 738 | - } | ||
| 739 | -}; | ||
| 740 | - | ||
| 741 | -module.exports = QQMapWX; | ||
| 742 | \ No newline at end of file | 0 | \ No newline at end of file |
utils/qqmap-wx-jssdk.min.js
0 → 100644
| 1 | +var ERROR_CONF={KEY_ERR:311,KEY_ERR_MSG:'key格式错误',PARAM_ERR:310,PARAM_ERR_MSG:'请求参数信息有误',SYSTEM_ERR:600,SYSTEM_ERR_MSG:'系统错误',WX_ERR_CODE:1000,WX_OK_CODE:200};var BASE_URL='https://apis.map.qq.com/ws/';var URL_SEARCH=BASE_URL+'place/v1/search';var URL_SUGGESTION=BASE_URL+'place/v1/suggestion';var URL_GET_GEOCODER=BASE_URL+'geocoder/v1/';var URL_CITY_LIST=BASE_URL+'district/v1/list';var URL_AREA_LIST=BASE_URL+'district/v1/getchildren';var URL_DISTANCE=BASE_URL+'distance/v1/';var EARTH_RADIUS=6378136.49;var Utils={location2query(data){if(typeof data=='string'){return data}var query='';for(var i=0;i<data.length;i++){var d=data[i];if(!!query){query+=';'}if(d.location){query=query+d.location.lat+','+d.location.lng}if(d.latitude&&d.longitude){query=query+d.latitude+','+d.longitude}}return query},rad(d){return d*Math.PI/180.0},getEndLocation(location){var to=location.split(';');var endLocation=[];for(var i=0;i<to.length;i++){endLocation.push({lat:parseFloat(to[i].split(',')[0]),lng:parseFloat(to[i].split(',')[1])})}return endLocation},getDistance(latFrom,lngFrom,latTo,lngTo){var radLatFrom=this.rad(latFrom);var radLatTo=this.rad(latTo);var a=radLatFrom-radLatTo;var b=this.rad(lngFrom)-this.rad(lngTo);var distance=2*Math.asin(Math.sqrt(Math.pow(Math.sin(a/ 2), 2) + Math.cos(radLatFrom) * Math.cos(radLatTo) * Math.pow(Math.sin(b /2),2)));distance=distance*EARTH_RADIUS;distance=Math.round(distance*10000)/10000;return parseFloat(distance.toFixed(0))},getWXLocation(success,fail,complete){wx.getLocation({type:'gcj02',success:success,fail:fail,complete:complete})},getLocationParam(location){if(typeof location=='string'){var locationArr=location.split(',');if(locationArr.length===2){location={latitude:location.split(',')[0],longitude:location.split(',')[1]}}else{location={}}}return location},polyfillParam(param){param.success=param.success||function(){};param.fail=param.fail||function(){};param.complete=param.complete||function(){}},checkParamKeyEmpty(param,key){if(!param[key]){var errconf=this.buildErrorConfig(ERROR_CONF.PARAM_ERR,ERROR_CONF.PARAM_ERR_MSG+key+'参数格式有误');param.fail(errconf);param.complete(errconf);return true}return false},checkKeyword(param){return!this.checkParamKeyEmpty(param,'keyword')},checkLocation(param){var location=this.getLocationParam(param.location);if(!location||!location.latitude||!location.longitude){var errconf=this.buildErrorConfig(ERROR_CONF.PARAM_ERR,ERROR_CONF.PARAM_ERR_MSG+' location参数格式有误');param.fail(errconf);param.complete(errconf);return false}return true},buildErrorConfig(errCode,errMsg){return{status:errCode,message:errMsg}},handleData(param,data,feature){if(feature==='search'){var searchResult=data.data;var searchSimplify=[];for(var i=0;i<searchResult.length;i++){searchSimplify.push({id:searchResult[i].id||null,title:searchResult[i].title||null,latitude:searchResult[i].location&&searchResult[i].location.lat||null,longitude:searchResult[i].location&&searchResult[i].location.lng||null,address:searchResult[i].address||null,category:searchResult[i].category||null,tel:searchResult[i].tel||null,adcode:searchResult[i].ad_info&&searchResult[i].ad_info.adcode||null,city:searchResult[i].ad_info&&searchResult[i].ad_info.city||null,district:searchResult[i].ad_info&&searchResult[i].ad_info.district||null,province:searchResult[i].ad_info&&searchResult[i].ad_info.province||null})}param.success(data,{searchResult:searchResult,searchSimplify:searchSimplify})}else if(feature==='suggest'){var suggestResult=data.data;var suggestSimplify=[];for(var i=0;i<suggestResult.length;i++){suggestSimplify.push({adcode:suggestResult[i].adcode||null,address:suggestResult[i].address||null,category:suggestResult[i].category||null,city:suggestResult[i].city||null,district:suggestResult[i].district||null,id:suggestResult[i].id||null,latitude:suggestResult[i].location&&suggestResult[i].location.lat||null,longitude:suggestResult[i].location&&suggestResult[i].location.lng||null,province:suggestResult[i].province||null,title:suggestResult[i].title||null,type:suggestResult[i].type||null})}param.success(data,{suggestResult:suggestResult,suggestSimplify:suggestSimplify})}else if(feature==='reverseGeocoder'){var reverseGeocoderResult=data.result;var reverseGeocoderSimplify={address:reverseGeocoderResult.address||null,latitude:reverseGeocoderResult.location&&reverseGeocoderResult.location.lat||null,longitude:reverseGeocoderResult.location&&reverseGeocoderResult.location.lng||null,adcode:reverseGeocoderResult.ad_info&&reverseGeocoderResult.ad_info.adcode||null,city:reverseGeocoderResult.address_component&&reverseGeocoderResult.address_component.city||null,district:reverseGeocoderResult.address_component&&reverseGeocoderResult.address_component.district||null,nation:reverseGeocoderResult.address_component&&reverseGeocoderResult.address_component.nation||null,province:reverseGeocoderResult.address_component&&reverseGeocoderResult.address_component.province||null,street:reverseGeocoderResult.address_component&&reverseGeocoderResult.address_component.street||null,street_number:reverseGeocoderResult.address_component&&reverseGeocoderResult.address_component.street_number||null,recommend:reverseGeocoderResult.formatted_addresses&&reverseGeocoderResult.formatted_addresses.recommend||null,rough:reverseGeocoderResult.formatted_addresses&&reverseGeocoderResult.formatted_addresses.rough||null};if(reverseGeocoderResult.pois){var pois=reverseGeocoderResult.pois;var poisSimplify=[];for(var i=0;i<pois.length;i++){poisSimplify.push({id:pois[i].id||null,title:pois[i].title||null,latitude:pois[i].location&&pois[i].location.lat||null,longitude:pois[i].location&&pois[i].location.lng||null,address:pois[i].address||null,category:pois[i].category||null,adcode:pois[i].ad_info&&pois[i].ad_info.adcode||null,city:pois[i].ad_info&&pois[i].ad_info.city||null,district:pois[i].ad_info&&pois[i].ad_info.district||null,province:pois[i].ad_info&&pois[i].ad_info.province||null})}param.success(data,{reverseGeocoderResult:reverseGeocoderResult,reverseGeocoderSimplify:reverseGeocoderSimplify,pois:pois,poisSimplify:poisSimplify})}else{param.success(data,{reverseGeocoderResult:reverseGeocoderResult,reverseGeocoderSimplify:reverseGeocoderSimplify})}}else if(feature==='geocoder'){var geocoderResult=data.result;var geocoderSimplify={title:geocoderResult.title||null,latitude:geocoderResult.location&&geocoderResult.location.lat||null,longitude:geocoderResult.location&&geocoderResult.location.lng||null,adcode:geocoderResult.ad_info&&geocoderResult.ad_info.adcode||null,province:geocoderResult.address_components&&geocoderResult.address_components.province||null,city:geocoderResult.address_components&&geocoderResult.address_components.city||null,district:geocoderResult.address_components&&geocoderResult.address_components.district||null,street:geocoderResult.address_components&&geocoderResult.address_components.street||null,street_number:geocoderResult.address_components&&geocoderResult.address_components.street_number||null,level:geocoderResult.level||null} | ||
| 2 | +param.success(data,{geocoderResult:geocoderResult,geocoderSimplify:geocoderSimplify})}else if(feature==='getCityList'){var provinceResult=data.result[0];var cityResult=data.result[1];var districtResult=data.result[2];param.success(data,{provinceResult:provinceResult,cityResult:cityResult,districtResult:districtResult})}else if(feature==='getDistrictByCityId'){var districtByCity=data.result[0];param.success(data,districtByCity)}else if(feature==='calculateDistance'){var calculateDistanceResult=data.result.elements;var distance=[];for(var i=0;i<calculateDistanceResult.length;i++){distance.push(calculateDistanceResult[i].distance)}param.success(data,{calculateDistanceResult:calculateDistanceResult,distance:distance})}else{param.success(data)}},buildWxRequestConfig(param,options,feature){var that=this;options.header={"content-type":"application/json"};options.method='GET';options.success=function(res){var data=res.data;if(data.status===0){that.handleData(param,data,feature)}else{param.fail(data)}};options.fail=function(res){res.statusCode=ERROR_CONF.WX_ERR_CODE;param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,res.errMsg))};options.complete=function(res){var statusCode=+res.statusCode;switch(statusCode){case ERROR_CONF.WX_ERR_CODE:{param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,res.errMsg));break}case ERROR_CONF.WX_OK_CODE:{var data=res.data;if(data.status===0){param.complete(data)}else{param.complete(that.buildErrorConfig(data.status,data.message))}break}default:{param.complete(that.buildErrorConfig(ERROR_CONF.SYSTEM_ERR,ERROR_CONF.SYSTEM_ERR_MSG))}}} | ||
| 3 | +return options},locationProcess(param,locationsuccess,locationfail,locationcomplete){var that=this;locationfail=locationfail||function(res){res.statusCode=ERROR_CONF.WX_ERR_CODE;param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,res.errMsg))};locationcomplete=locationcomplete||function(res){if(res.statusCode==ERROR_CONF.WX_ERR_CODE){param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,res.errMsg))}};if(!param.location){that.getWXLocation(locationsuccess,locationfail,locationcomplete)}else if(that.checkLocation(param)){var location=Utils.getLocationParam(param.location);locationsuccess(location)}}};class QQMapWX{constructor(options){if(!options.key){throw Error('key值不能为空')}this.key=options.key};search(options){var that=this;options=options||{};Utils.polyfillParam(options);if(!Utils.checkKeyword(options)){return}var requestParam={keyword:options.keyword,orderby:options.orderby||'_distance',page_size:options.page_size||10,page_index:options.page_index||1,output:'json',key:that.key};if(options.address_format){requestParam.address_format=options.address_format}if(options.filter){requestParam.filter=options.filter}var distance=options.distance||"1000";var auto_extend=options.auto_extend||1;var region=null;var rectangle=null;if(options.region){region=options.region}if(options.rectangle){rectangle=options.rectangle}var locationsuccess=function(result){if(region&&!rectangle){requestParam.boundary="region("+region+","+auto_extend+","+result.latitude+","+result.longitude+")"}else if(rectangle&&!region){requestParam.boundary="rectangle("+rectangle+")"}else{requestParam.boundary="nearby("+result.latitude+","+result.longitude+","+distance+","+auto_extend+")"}wx.request(Utils.buildWxRequestConfig(options,{url:URL_SEARCH,data:requestParam},'search'))};Utils.locationProcess(options,locationsuccess)};getSuggestion(options){var that=this;options=options||{};Utils.polyfillParam(options);if(!Utils.checkKeyword(options)){return}var requestParam={keyword:options.keyword,region:options.region||'全国',region_fix:options.region_fix||0,policy:options.policy||0,page_size:options.page_size||10,page_index:options.page_index||1,get_subpois:options.get_subpois||0,output:'json',key:that.key};if(options.address_format){requestParam.address_format=options.address_format}if(options.filter){requestParam.filter=options.filter}if(options.location){var locationsuccess=function(result){requestParam.location=result.latitude+','+result.longitude;wx.request(Utils.buildWxRequestConfig(options,{url:URL_SUGGESTION,data:requestParam},"suggest"))};Utils.locationProcess(options,locationsuccess)}else{wx.request(Utils.buildWxRequestConfig(options,{url:URL_SUGGESTION,data:requestParam},"suggest"))}};reverseGeocoder(options){var that=this;options=options||{};Utils.polyfillParam(options);var requestParam={coord_type:options.coord_type||5,get_poi:options.get_poi||0,output:'json',key:that.key};if(options.poi_options){requestParam.poi_options=options.poi_options}var locationsuccess=function(result){requestParam.location=result.latitude+','+result.longitude;wx.request(Utils.buildWxRequestConfig(options,{url:URL_GET_GEOCODER,data:requestParam},'reverseGeocoder'))};Utils.locationProcess(options,locationsuccess)};geocoder(options){var that=this;options=options||{};Utils.polyfillParam(options);if(Utils.checkParamKeyEmpty(options,'address')){return}var requestParam={address:options.address,output:'json',key:that.key};if(options.region){requestParam.region=options.region}wx.request(Utils.buildWxRequestConfig(options,{url:URL_GET_GEOCODER,data:requestParam},'geocoder'))};getCityList(options){var that=this;options=options||{};Utils.polyfillParam(options);var requestParam={output:'json',key:that.key};wx.request(Utils.buildWxRequestConfig(options,{url:URL_CITY_LIST,data:requestParam},'getCityList'))};getDistrictByCityId(options){var that=this;options=options||{};Utils.polyfillParam(options);if(Utils.checkParamKeyEmpty(options,'id')){return}var requestParam={id:options.id||'',output:'json',key:that.key};wx.request(Utils.buildWxRequestConfig(options,{url:URL_AREA_LIST,data:requestParam},'getDistrictByCityId'))};calculateDistance(options){var that=this;options=options||{};Utils.polyfillParam(options);if(Utils.checkParamKeyEmpty(options,'to')){return}var requestParam={mode:options.mode||'walking',to:Utils.location2query(options.to),output:'json',key:that.key};if(options.from){options.location=options.from}if(requestParam.mode=='straight'){var locationsuccess=function(result){var locationTo=Utils.getEndLocation(requestParam.to);var data={message:"query ok",result:{elements:[]},status:0};for(var i=0;i<locationTo.length;i++){data.result.elements.push({distance:Utils.getDistance(result.latitude,result.longitude,locationTo[i].lat,locationTo[i].lng),duration:0,from:{lat:result.latitude,lng:result.longitude},to:{lat:locationTo[i].lat,lng:locationTo[i].lng}})}var calculateResult=data.result.elements;var distanceResult=[];for(var i=0;i<calculateResult.length;i++){distanceResult.push(calculateResult[i].distance)}return options.success(data,{calculateResult:calculateResult,distanceResult:distanceResult})};Utils.locationProcess(options,locationsuccess)}else{var locationsuccess=function(result){requestParam.from=result.latitude+','+result.longitude;wx.request(Utils.buildWxRequestConfig(options,{url:URL_DISTANCE,data:requestParam},'calculateDistance'))};Utils.locationProcess(options,locationsuccess)}}};module.exports=QQMapWX; | ||
| 0 | \ No newline at end of file | 4 | \ No newline at end of file |