【问题标题】:AJAX request from Google Places API returns null来自 Google Places API 的 AJAX 请求返回 null
【发布时间】:2012-09-30 19:35:00
【问题描述】:

我正在尝试以 JSON 格式从 Google Places API 检索地点列表。我正在发送 AJAX 请求。

GET 请求发送正确的参数并收到 200 OK 成功消息,但没有响应(每个 firebug)。

您知道如何检索 JSON 中的地点列表或将 JSONP 转换为 JSON 吗?

photos.js

$.ajax({
  type: 'GET',
  url:'https://maps.googleapis.com/maps/api/place/search/json',
  dataType: 'json',
  data: {
   'location' : data.location.latitude+","+data.location.longitude,
   'radius' : 500,
   'key' : "mykeyhere",
   'sensor' : "false",
   'keyword' : "hotel"
   },

    success: function(hotel){
    console.log(hotel);
 }
});

我尝试将 dataType 更改为 jsonp 并且我能够得到所有列表的响应,但我收到 "html_attributions" : [] 错误,因为它需要 JSON。响应如 https://developers.google.com/places/documentation/search 中所述,但我得到一个无法识别html_attributions的firebug错误

【问题讨论】:

标签: javascript ruby-on-rails-3 jquery google-places-api


【解决方案1】:

好的!我有一个解决方案(感谢 Chris Green)! 就用这个

function produceSearch(term) {
    var _params = {
        radius : 11000,
        name : term,
        location : app.modules.mapsProvider.getLatLng(),
        key : 'KEY'
    };
    var service = new google.maps.places.PlacesService(map_inst);
    service.search(_params, requestSucceeded);
}

代替jQuery Ajax函数:)

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

【讨论】:

    猜你喜欢
    • 2013-11-29
    • 2013-09-12
    • 2016-03-31
    • 1970-01-01
    • 2012-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多