获取Google Places附近搜索的JSON [英] Getting JSON of Google Places Nearby Search

查看:85
本文介绍了获取Google Places附近搜索的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得Google Places API的附近搜索结果json。我收到此错误:请求的资源上没有Access-Control-Allow-Origin标头。
我使用的代码是:



 < html> < HEAD> < title>地方搜索< / title> < script type =text / javascriptsrc =lib / jquery-2.1.1.min.js>< / 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);}); < /脚本> < /头> <身体GT; < h1> Google放置测试< / h1> < / body>< / html>  


我甚至在jsonlint.com网站上发布了这个网址,正确的json,但我不明白为什么它不能在我的浏览器上运行。 解决方案

不要使用< href =https://developers.google.com/places/web-service/ =nofollow>将javascript放在web服务 api中,使用 Places Library



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


  • I'm trying to get the result json of a Nearby Search of Google Places API. I'm getting this error : "No Access-Control-Allow-Origin header is present on the requested resource."
    The code I'm using is :

    <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>

    I even posted the url on jsonlint.com website and it gave me the correct json, but I don't get why it doesn't work on my browser

    解决方案

    Don't use the Places web service api from javascript, use the Places Library.

    Related issues in the issue tracker (marked as "WorkingAsIntended"):

    这篇关于获取Google Places附近搜索的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆