问题::如何在我的浏览器中调用Google Places服务器端API / textsearch /而不是使用Google Places JS库时,得到类似的JSON响应?>
这是服务器端Google Places API / textsearch / https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants+pyrmont&key=AIzaSyAXPJDWXhzlAY0N8mMUcgFJ6yNSEd0vMg8
以下是示例代码: 我尝试用console.log()JSON,但是无法获取任何JSON记录到控制台。
var map;
var service;
var infowindow;
function initialize() {
var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);
map = new google.maps.Map(document.getElementById('map'), {
center: pyrmont,
zoom: 15
});
var request = {
location: pyrmont,
radius: '500',
query: 'restaurant'
};
service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
createMarker(results[i]);
}
console.log(place.id)
}
}
如果有帮助,请参阅以下文档:https://developers.google.com/maps/documentation/javascript/places#TextSearchRequests
感谢您提供的任何帮助!