javascript - Google Places API 获取详细信息 - 无效请求

标签 javascript google-places-api

所以我正在尝试根据 google places 文本搜索获取详细信息。我的文本搜索工作正常,但为了获取详细信息,我不断收到“无效请求”。

我遵循了文档中的示例以及其他人的示例,但无济于事,我失败了....

这是我的文本搜索,它正在运行。

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有关详细信息和示例。

关于javascript - Google Places API 获取详细信息 - 无效请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36710345/

相关文章:

javascript - Google Places API Web 服务服务器端解决方案

java - Android - 获取附近地点的列表

android - 将 PlaceAutocompleteFragment 添加到 fragment 会引发错误

javascript - HighCharts:饼图切片需要背景图片

javascript - 如何在 Node 中使用coffescript导出类

Javascript:如何识别 "div"是否溢出?

javascript - 自定义编码字符串

javascript - 如何使用替代变量编写这个 for 循环?

python - 在 Google Places api 中搜索附近的 lat_lng (python)

google-maps - 嵌入式 Google map 无法在 WebView 中获取当前位置