0
var placesAPI = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=32.8400,-117.2769&radius=500&types=museum&sensor=true&key=my_key_here";
$.getJSON(placesAPI, function (json) {
    var address = json.results[0].name;
    console.log('Name : ', name);
});

I am trying the above code with no success. I do put in my API key and I get the json results on the webpage but when I try to parse them I get an error "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. "

How do I parse the JSON?

Phil
  • 157,677
  • 23
  • 242
  • 245
user970044
  • 47
  • 4
  • 9
  • 3
    Parsing the JSON is not the problem. Getting it is. You should probably use the library provided by Google to get the data: https://developers.google.com/maps/documentation/javascript/tutorial. – Felix Kling Nov 22 '13 at 06:28

1 Answers1

0

Try the code below. I added &callback=? to your url as per the instruction is the following post.

var placesAPI = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=32.8400,-117.2769&radius=500&types=museum&sensor=true&key=my_key_here&callback=?";
$.getJSON(placesAPI, function (json) {
    var address = json.results[0].name;
    console.log('Name : ', name);
});
Community
  • 1
  • 1
Ben Pearce
  • 6,884
  • 18
  • 70
  • 127