Skip to content

Commit

Permalink
地图请求备用key值
Browse files Browse the repository at this point in the history
  • Loading branch information
bailicangdu committed Jun 5, 2017
1 parent e4d6c70 commit d042f4e
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions prototype/addressComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AddressComponent extends BaseComponent {
this.tencentkey = 'RLHBZ-WMPRP-Q3JDS-V2IQA-JNRFH-EJBHL';
this.tencentkey2 = 'RRXBZ-WC6KF-ZQSJT-N2QU7-T5QIT-6KF5X';
this.baidukey = 'fjke3YUipM9N64GdOIh1DNeK2APO2WcT';
this.baidukey2 = 'fjke3YUipM9N64GdOIh1DNeK2APO2WcT';
}
//获取定位地址
async guessPosition(req){
Expand All @@ -25,10 +26,17 @@ class AddressComponent extends BaseComponent {
ip = '116.226.184.83';
}
try{
const result = await this.fetch('http://apis.map.qq.com/ws/location/v1/ip', {
let result;
result = await this.fetch('http://apis.map.qq.com/ws/location/v1/ip', {
ip,
key: this.tencentkey,
})
if (result.status !== 0) {
result = await this.fetch('http://apis.map.qq.com/ws/location/v1/ip', {
ip,
key: this.tencentkey2,
})
}
if (result.status == 0) {
const cityInfo = {
lat: result.result.location.lat,
Expand All @@ -38,22 +46,8 @@ class AddressComponent extends BaseComponent {
cityInfo.city = cityInfo.city.replace(/市$/, '');
resolve(cityInfo)
}else{
const result = await this.fetch('http://apis.map.qq.com/ws/location/v1/ip', {
ip,
key: this.tencentkey2,
})
if (result.status == 0) {
const cityInfo = {
lat: result.result.location.lat,
lng: result.result.location.lng,
city: result.result.ad_info.city,
}
cityInfo.city = cityInfo.city.replace(/市$/, '');
resolve(cityInfo)
}else{
console.log('定位失败', result)
reject('定位失败');
}
console.log('定位失败', result)
reject('定位失败');
}
}catch(err){
reject(err);
Expand Down Expand Up @@ -81,12 +75,21 @@ class AddressComponent extends BaseComponent {
//测量距离
async getDistance(from, to, type){
try{
const res = await this.fetch('http://api.map.baidu.com/routematrix/v2/driving', {
let res;
res = await this.fetch('http://api.map.baidu.com/routematrix/v2/driving', {
ak: this.baidukey,
output: 'json',
origins: from,
destinations: to,
})
if(res.status !== 0){
res = await this.fetch('http://api.map.baidu.com/routematrix/v2/driving', {
ak: this.baidukey2,
output: 'json',
origins: from,
destinations: to,
})
}
if(res.status == 0){
const positionArr = [];
let timevalue;
Expand Down

0 comments on commit d042f4e

Please sign in to comment.