【发布时间】:2014-02-25 12:10:42
【问题描述】:
这是我的代码:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
var API = "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true";
var API = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=chicken+greenvile+sc&sensor=true";
$.getJSON(API, function (data) {
console.log(data);
});
</script>
如果我注释掉第二个 var API,我会在控制台日志中得到返回结果,没有问题。如果我取消注释第二个,我会得到“请求的资源上不存在'Access-Control-Allow-Origin'标头”。 ..所以如果我添加“回调=?”到第二个 var API 的末尾,我得到“Uncaught SyntaxError: Unexpected token :”...返回的 JSON 是哪个,但格式不正确?...我不知道。我究竟做错了什么?我只想能够像 Geocode API 一样使用 Places API。地理编码完美运行...
【问题讨论】:
-
试试this
-
@shyamnathan 该链接没有任何意义。
-
我昨天才开始尝试这些东西。到目前为止,我只使用了 100 个请求。这真的很奇怪。另一件事是,我什至没有在上面的两个 API 链接中指定密钥。但是上面的仍然有效。通常我应该使用这样的东西:maps.googleapis.com/maps/api/place/textsearch/json?query=chicken+greenvile+sc&sensor=true&key=(mykeyhere)
-
请阅读documentation(用于网络服务)或for the Places library,Places API 需要密钥。
标签: javascript jquery json google-maps-api-3