【发布时间】:2013-12-06 22:53:26
【问题描述】:
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);
});
我正在尝试上面的代码,但没有成功。我确实输入了我的 API 密钥,并在网页上获得了 json 结果,但是当我尝试解析它们时,我收到一个错误“请求的资源上不存在'Access-Control-Allow-Origin'标头。来源'null'因此不允许访问。"
如何解析 JSON?
【问题讨论】:
-
解析 JSON 不是问题。得到它是。您可能应该使用 Google 提供的库来获取数据:developers.google.com/maps/documentation/javascript/tutorial。
标签: javascript jquery json