2012-09-27 112 views
0

我试图从JSON中的Google Places API检索地点列表。我正在发送一个AJAX请求。来自Google Places API的AJAX请求返回null

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

你知道我如何检索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); 
} 
}); 

我试图改变数据类型设置为JSONP,我能得到与所有房源的响应,但我得到"html_attributions" : []错误,因为它期待JSON.The反应是描述在https://developers.google.com/places/documentation/search,但我得到一个不识别的萤火虫错误html_attributions

+0

您是否尝试过使用[商家信息库(https://developers.google.com/maps/documentation/ javascript /地方)的谷歌地图JavaScript API V3呢? –

+0

我有同样的问题:( 这是我的问题http://stackoverflow.com/questions/12660723/search-in-google-places-via-ajax-gives-empty-results-but-not-in-浏览器 –

回答

0

好的!我有一个解决方案(感谢克里斯格林)! 只要使用这个

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