Google 地点 API 获取详细信息 - 请求无效
Google Places API get details - Invalid Request
所以我正在尝试根据 google 地点文本搜索获取详细信息。我的文本搜索工作正常,但为了获取详细信息,我不断获取 "Invalid Request".
我遵循了文档中的示例以及其他人的示例,但无济于事,我失败了....
这是我的文本搜索,正在运行。
var lat = '43.09182244507046'
var lng = '-89.48985488807972'
var places;
function initialize() {
var location = new google.maps.LatLng(lat,lng);
var map = new google.maps.Map(document.getElementById('map'),{
center: location,
zoom: 15
});
var request = {
location: location,
radius: '50000',
query: 'food'
};
var callback = function (results, status) {
places = results;
console.log(status);
console.log(places);
}
var service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
}
这是我的地点详情搜索,它的请求状态无效
var place_details;
function getDetails() {
var location = new google.maps.LatLng(lat,lng);
var map = new google.maps.Map(document.getElementById('map'),{
center: location,
zoom: 15
});
var callback = function (results, status) {
place_details = results;
};
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: "8deae188679ff8b9344085de5360a769879240f9"}, function(place, status){
place_details = place;
console.log(place_details);
console.log(status);
}
);
}
我在那里有 if(status === google.maps.places.PlaceService.OK) 。所以这不是问题,以防有人发现。
任何帮助将不胜感激...我希望它能工作!
8deae188679ff8b9344085de5360a769879240f9
不是地点 ID。我怀疑您使用的 PlaceResult.id
不适用于详细信息请求并且是 deprecated.
改为使用PlaceResult.place_id
。有关详细信息和示例,请参阅 the documentation。
所以我正在尝试根据 google 地点文本搜索获取详细信息。我的文本搜索工作正常,但为了获取详细信息,我不断获取 "Invalid Request".
我遵循了文档中的示例以及其他人的示例,但无济于事,我失败了....
这是我的文本搜索,正在运行。
var lat = '43.09182244507046'
var lng = '-89.48985488807972'
var places;
function initialize() {
var location = new google.maps.LatLng(lat,lng);
var map = new google.maps.Map(document.getElementById('map'),{
center: location,
zoom: 15
});
var request = {
location: location,
radius: '50000',
query: 'food'
};
var callback = function (results, status) {
places = results;
console.log(status);
console.log(places);
}
var service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
}
这是我的地点详情搜索,它的请求状态无效
var place_details;
function getDetails() {
var location = new google.maps.LatLng(lat,lng);
var map = new google.maps.Map(document.getElementById('map'),{
center: location,
zoom: 15
});
var callback = function (results, status) {
place_details = results;
};
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: "8deae188679ff8b9344085de5360a769879240f9"}, function(place, status){
place_details = place;
console.log(place_details);
console.log(status);
}
);
}
我在那里有 if(status === google.maps.places.PlaceService.OK) 。所以这不是问题,以防有人发现。
任何帮助将不胜感激...我希望它能工作!
8deae188679ff8b9344085de5360a769879240f9
不是地点 ID。我怀疑您使用的 PlaceResult.id
不适用于详细信息请求并且是 deprecated.
改为使用PlaceResult.place_id
。有关详细信息和示例,请参阅 the documentation。