Google Places API返回状态码200,不包含数据或响应头

时间:2019-05-11 01:21:19

标签: javascript google-maps proxy cors axios

我有一个axios调用,它调用了Google Places API。它与在我的客户端package.json中定义的代理一起使用。但是,当我将基本网址添加到我的axios请求中时,它可以工作,但是google只返回状态码为200的对象,没有数据或响应头。

我的以下代码在开发环境中可与代理一起使用,但在gitpages中失败。解决方法是,我尝试按如下所示重新格式化url,但这将使API仅返回状态码200,而没有数据或响应头。

https://maps.googleapis.com/maps/api/place/details/json?placeid=" + placeId+"&key=APIKEY

package.json

  "proxy": "https://maps.googleapis.com",

API.js

import axios from "axios";


export default {
   getRestaurantOrGroceryAPI: function(latitude,longitude,searchType,ethnicity) {
    return axios.get("/maps/api/place/nearbysearch/json?location=" + latitude+","+longitude+"&radius=50000&type="+searchType+"&keyword="+ethnicity+"&key=APIKEY" )
  },
  getApiData: function(latitude,longitude,searchType) {
    return axios.get("/maps/api/place/nearbysearch/json?location=" + latitude+","+longitude+"&radius=10000&type="+searchType+"&key=APIKEY" )
  },
  getCid: function(placeId) {
    return axios.get("/maps/api/place/details/json?placeid=" + placeId+"&key=APIKEY" )
  }

};

0 个答案:

没有答案
相关问题