elasticsearch入門系列">elasticsearch入門系列
608
2022-05-30
前言
1.相關API
逆地址解析:提供由經緯度到文字地址及相關位置信息的轉換能力,廣泛應用于物流、出行、O2O、社交等場景。服務響應速度快、穩定,支撐億級調用。
可以滿足以下相關業務場景:
滿足傳統對省市區、鄉鎮村、門牌號、道路及交叉口、河流、湖泊、橋、poi列表的需求。
提供通過知名地點、地標組合形成的易于理解的地址,如:北京市海淀區中鋼國際廣場(歐美匯購物中心北)。
提供精準的商圈、知名的大型區域、附近知名的一級地標、代表當前位置的二級地標等。
請求地址:https://apis.map.qq.com/ws/geocoder/v1/?location=
請求參數:
詳情請看相關接口網址:https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
一、獲取位置和城市信息
獲取位置方法:getLocationInfo
getLocationInfo() { var _this = this app.showLoading("拉取路線列表") wx.getLocation({ type: 'gcj02', success: function (res) { var locationInfo = _this.data.locationInfo locationInfo.latitude = res.latitude locationInfo.longitude = res.longitude // 調用接口 qqmap.reverseGeocoder({ location: { latitude: locationInfo.latitude, longitude: locationInfo.longitude }, success: function (res) { locationInfo.city = res.result.address_component.city locationInfo.address = res.result.formatted_addresses.recommend _this.setData({ locationInfo: locationInfo }) _this.getStationList() }, fail: function (res) { console.log(res); app.hideLoading(locationInfo) }, complete: function (res) { // complete // console.log(_this.data.locationInfo) } }) } }) },
逆地址解析方法:reverseGeocoder
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 })); }; Utils.locationProcess(options, locationsuccess); }
Utils相關工具類:
/** * 回調函數默認處理 */ polyfillParam(param) { param.success = param.success || function () { }; param.fail = param.fail || function () { }; param.complete = param.complete || function () { }; }, /** * 構造微信請求參數,公共屬性處理 * * @param {Object} param 接口參數 * @param {Object} param 配置項 */ buildWxRequestConfig(param, options) { var that = this; options.header = { "content-type": "application/json" }; options.method = 'GET'; options.success = function (res) { var data = res.data; if (data.status === 0) { param.success(data); } else { param.fail(data); } }; options.fail = function (res) { res.statusCode = ERROR_CONF.WX_ERR_CODE; param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, result.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)); } } } 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); } } /** * 構造錯誤數據結構 * @param {Number} errCode 錯誤碼 * @param {Number} errMsg 錯誤描述 */ buildErrorConfig(errCode, errMsg) { return { status: errCode, message: errMsg }; }, /** * 獲取location參數 */ 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; },
小程序
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。