首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Places API

Google Places API
EN

Stack Overflow用户
提问于 2011-07-30 03:22:04
回答 1查看 2K关注 0票数 0

我正在尝试使用jQuery调用Google Places API1,但似乎因为跨域安全问题而失败。我尝试将这个请求作为一个JSONP请求,它运行了,但是服务器直接返回了JSON,所以在jQuery中解析失败。有人找到解决这个问题的办法了吗?

代码语言:javascript
复制
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
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-23 05:40:52

@Jeremy:我可以为你发布结束语。

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

Querying Google Places API using jQuery

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6878007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档