Ajax和Places API获取请求

时间:2013-11-14 10:17:33

标签: jquery ajax json google-places-api

我无法向Google Places API提供AJAX请求。代码:

$.ajax({
    type: 'GET',
    url:'http://maps.googleapis.com/maps/api/place/textsearch/json?',
    dataType: 'json',
    data: {
        'query' : "restaurants+in+" + cityname,
        'key' : MyPublicKey,
        'sensor' : "false"
    },
    success: function(restaurans) {
        console.log(restaurants);
    }
});

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我想REST API不能像这样使用(我猜一个原因应该是CORS)

请参阅Google Places API

  

希望在JavaScript应用程序中使用此服务?看看   放置Google Maps API v3的库。

应该引导你

https://developers.google.com/maps/documentation/javascript/places

及其“文本搜索请求”部分提供了带有Google文本搜索服务对象的示例