【问题标题】:I can get Google Geocode API to work, but not the Google Place API我可以让 Google Geocode API 工作,但不能让 Google Place API
【发布时间】: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。地理编码完美运行...

【问题讨论】:

标签: javascript jquery json google-maps-api-3


【解决方案1】:

在调用 Maps API 时会调用 Places API。它是类似于天气、绘图或几何的库之一。

https://maps.googleapis.com/maps/api/js?key=(YOUR KEY)&sensor=false&libraries=*places*

添加了一个库,Places API 可以在您的应用中使用

【讨论】:

  • 无论有没有密钥,我都会得到相同的结果。
  • 你能发布你的整个代码吗?您使用的是什么类型的服务器?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-03
相关资源
最近更新 更多