dsxay48646 2019-01-18 05:35
浏览 38

让我的服务器向Google Places API发出请求,然后将信息传递给我的Vue.js前端

Long story short, I'm trying to use Google Places API in order to get sights based on latitude and longitude. When I tried to use that API for the first time, I tried using axios on the front end to make a GET request like this:

axios.get('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=42.150527,24.746477&radius=1500&type=art_gallery&key=')
.then(response => {
    console.log(response)
})

However, I kept getting a CORS error:

"has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is 
present on the requested resource."

So I was wondering what am I doing wrong and decided to recheck the documentation and found this:

"Each of the services is accessed as an HTTP request, and returns either an JSON or 
XML response. All requests to a Places service must use the https:// protocol, and 
include an API key."

So after consulting stackoverflow, I was told that the request must come from a back end server and not a browser. It was explained to me that my server must make a request to Google Places API and then my front end must make a request to my server so that I could get the sights information.

I do have a PHP/Laravel back end used for storing users, latitude and longitude markers and locations, however, I have no idea how to make that request from my server to the Google Places API.

This is my first time using APIs that require such requisite. So far I've only made my own APIs using PHP and Laravel which have endpoints that return information.

What I'm trying to say it that I have absolutely no idea how to make my server make a request to the Google Places API.

Any information, explanations and documentation related to my problem would be really appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划