【问题标题】:Google Places APIGoogle 地方信息 API
【发布时间】:2011-09-23 05:40:52
【问题描述】:

我正在尝试使用 jQuery 调用 Google Places API1,但由于跨域安全问题,它似乎失败了。我试图使这个请求成为 JSONP 请求并且它运行但服务器直接返回 JSON,因此在 jQuery 中解析失败。有没有人找到解决方案?

var requestUrl = "https://maps.googleapis.com/maps/api/place/search/json?location=" +
                   location.coords.latitude + "," + location.coords.longitude + "&radius=100&types=restaurant&sensor=false&key=<<api key here>>";

// Called with
$.getJSON(requestUrl + "&callback=?", onLocateRestaurants);
// or
$.ajax({
    url: requestUrl,
    type: 'GET',
    dataType: 'jsonp',
    crossDomain: true,
    callback: 'test',
    contentType: 'application/json',
    success: onLocateRestaurants2,
    error: defaultErrorHandler
});

【问题讨论】:

  • Places API 不支持 JSON-P。有关详细信息,请参阅上面 Ken 链接的问题。
  • 你能把这些回答作为答案,这样我就可以结束这个问题了吗?

标签: jquery json cross-domain google-api


【解决方案1】:

@Jeremy:我可以为你发布最后的答案。

Places API 不支持 JSON-P。有关详细信息,请参阅以下问题(由 Ken Browning 链接):

Querying Google Places API using jQuery

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-02
    • 2020-11-29
    相关资源
    最近更新 更多