从Mapbox返回地点和地址

时间:2017-12-30 03:51:48

标签: javascript reactjs mapbox axios mapbox-gl

我正在使用mapbox地理编码器根据搜索输入返回点数。除了地名(例如星巴克)之外,我希望我的用户能够输入原始地址(例如123 Elm St.)。我的返回结果的函数在这里:

  geocodeThis(query) {
    const { homePoint } = this.state
    const accessToken = this.state.settings.accessToken
    axios.get('/geocoding/v5/mapbox.places/'+query+'.json?access_token='+accessToken+'&proximity='+homePoint.geometry.coordinates[0]+','+homePoint.geometry.coordinates[1])
      .then((response) => {
        this.setState({suggestions: response.data.features})
      })
      .catch((error) => {
        console.log(error);
      });
  }

0 个答案:

没有答案