javascript - 获取 Google Places Nearby Search 的 JSON

标签 javascript json google-maps google-places-api

我正在尝试获取 Google Places API 附近搜索的结果 json。我收到此错误:“请求的资源上不存在 Access-Control-Allow-Origin header 。”
我使用的代码是:

<html>
  <head>
    <title>Place searches</title>
    <script type="text/javascript" src="lib/jquery-2.1.1.min.js"></script>
    <script>
      
      var mJson = "http://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=AIzaSyCy639YCvWAzb3Sx0wkMzO5gxG-nHei4QU";
      $.getJSON(mJson,function(data){
        console.log(data);
      });

    </script>

  </head>
  <body>
    <h1>Google places test</h1>
  </body>
</html>
我什至在 jsonlint.com 网站上发布了 url,它给了我正确的 json,但我不明白为什么它在我的浏览器上不起作用

最佳答案

不要使用 Places web service来自javascript的api,使用Places Library .

问题跟踪器中的相关问题(标记为“WorkingAsIntended”):

关于javascript - 获取 Google Places Nearby Search 的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34028977/

相关文章:

javascript - NodeJS + MongoDB - 启动从 npm 安装的 mongodb 服务器实例

android - 在没有 Activity 的情况下使用 Google map 位置

kotlin - 我如何请求位置

javascript - 可扩展的谷歌地图覆盖

javascript - 如何使用 Rails 或 Javascript 提取 URL 内容

javascript - 如何使用ajax显示JSON

javascript - Node.js错误: write after end - AWS Polly

javascript - 正确循环 .each(function) 并将数字字符串格式化为电话号码

javascript - CoffeeScript 对 splat 和这个实现的好奇心

java - 谷歌数据流 : how to parse big file with valid JSON array from FileIO. 可读文件