1

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
Shailen Tuli
  • 13,815
  • 5
  • 40
  • 51
m0j1
  • 4,067
  • 8
  • 31
  • 54

1 Answers1

4

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

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

geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • Thanks, but I want to have a json from the nearby places to use it in my own app. I read the link but seems it doesn't give you json and loads the data on a google's map – m0j1 Dec 01 '15 at 20:06
  • Then you will need to proxy the data through your server or see if you can convince google to change that header. – geocodezip Dec 01 '15 at 20:22
  • I tried uploading and testing it from a server and not my local system and the result is the same and I get the same error – m0j1 Dec 01 '15 at 20:24
  • That doesn't sound like a proxy to me. – geocodezip Dec 01 '15 at 20:26
  • Seems I haven't correctly understood your solution, I'll appreciate if you can explain more. Thanks – m0j1 Dec 01 '15 at 20:29