2017-08-04 54 views
0

我試圖扭轉使用vue.js和谷歌API地址解析...reverseGeocoding在VUE

我LAT局域網的價值,但我真的希望使用LAT和局域網值來獲得城市的名字。我不知道如何....請幫助我,請查看下

Vue.use(VueAxios, axios) 

export default { 
    name: 'Position', 
    beforeCreate(){ 

    let googleApi = 'https://maps.googleapis.com/maps/api/geocode/json?latlng'; 
    let weatherApi = '' 
    let token  = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'; 
    let location = '수원시 장안구 영화동'; 

    Vue.axios.get(googleApi, { 
     params: { 
     address: location, 
     key: token 
     } 
    }) 
    .then(response => { 
     console.log(response.data.results); 
     console.log(response.data.results[0].address_components) 
     let currentPosition = response.data.results[0].geometry.location; 
     this.currentLatitude = currentPosition.lat; 
     this.currentLongitude = currentPosition.lng; 
     this.currentCity = response.data.results[0] 
    }) 
    .catch(error => { 
     console.log(error); 
    }); 
    }, 

    data(){ 
    return { 
      currentLatitude : null, 
      currentLongitude : null, 
      currentCity : '' 
      } 
     }, 

回答