简体   繁体   English

谷歌放置 API getDetails() 服务不返回任何位置的评级

[英]Google places API getDetails() service not returning ratings for any location

I've been trying to build a bicycle assistant and I'm trying to show the phone number and rating for the destination the user enters.我一直在尝试构建一个自行车助手,并试图显示用户输入目的地的电话号码和评级。

I have some code that gets me the entire request in the form below (copied from firefox console)我有一些代码可以让我以下面的形式获取整个请求(从 firefox 控制台复制)


address_components: Array(6) [ {…}, {…}, {…}, … ]
​
adr_address: "<span class=\"street-address\">Times Sq</span>, <span class=\"locality\">New York</span>, <span class=\"region\">NY</span>, <span class=\"country-name\">USA</span>"
​
formatted_address: "Times Sq, New York, NY, USA"
​
geometry: Object { location: {…}, viewport: {…} }
​
html_attributions: Array []
​
icon: "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/geocode-71.png"
​
icon_background_color: "#7B9EB0"
​
icon_mask_base_uri: "https://maps.gstatic.com/mapfiles/place_api/icons/v2/generic_pinlet"
​
name: "Times Square"
​
place_id: "ChIJO8I76FVYwokR2nYv8Wdvie0"
​
reference: "ChIJO8I76FVYwokR2nYv8Wdvie0"
​
types: Array [ "route" ]
​
url: "https://maps.google.com/?q=Times+Sq,+New+York,+NY,+USA&ftid=0x89c25855e83bc23b:0xed896f67f12f76da"
​
utc_offset: 
​
utc_offset_minutes: -240
​
vicinity: "Manhattan"

I get legitimate details for all the place IDs I search for, such as phone number and address.我获得了我搜索的所有地点 ID 的合法详细信息,例如电话号码和地址。 However, I do not get the rating for any of them.但是,我没有得到其中任何一个的评分。

I tried popular places too but no ratings field.我也尝试了受欢迎的地方,但没有评分字段。 I haven't added any field filters either.我也没有添加任何字段过滤器。 Below is my setup for the request for reference.以下是我的参考请求设置。


function fetchmoredeets(addr) {
    var loc = addr.split(' ').join('+')
    const URL = `https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api/place/textsearch/json?query=${loc}&key=(my_key)`
    // First get and parse the nearby regions

    async function fetcher(URL){
        const resp = await fetch(URL);
        return await resp.json()
    }

    var res, req;
    (async () => {
      req = await fetcher(URL);
      res = req.results;
      console.log("All deets helper:", res[0]);
      var deetsreq = {
              placeId: res[0].place_id,
            };

            var service = new google.maps.places.PlacesService(map);
            service.getDetails(deetsreq, callback);

            function callback(place, status) {
              if (status == google.maps.places.PlacesServiceStatus.OK) {
                console.log(place);
                document.getElementById("table-title").innerHTML = res[0].name
                var table = document.getElementById("deets-entries");
                var r = table.insertRow();
                r.insertCell().innerHTML =  place.address_components[1].short_name + ' ' + place.address_components[2].short_name; // addr

                r.insertCell().innerHTML= place.ratings; // rating
                if(place.formatted_phone_number==null){
                    r.insertCell().innerHTML= "NA";
                }
                else{
                    r.insertCell().innerHTML= place.formatted_phone_number;
                }
              }
            }


})()
}

Above, addr is a string with the address of the place (based on the user's selection from google's places autocomplete API)上面,addr 是一个带有地点地址的字符串(基于用户从谷歌的地点自动完成 API 中选择)

Any help would be great!任何帮助都会很棒! Thanks谢谢

The place id you used in your example ( ChIJO8I76FVYwokR2nYv8Wdvie0 ) returns "types" : [ "route" ] .您在示例中使用的地点 id ( ChIJO8I76FVYwokR2nYv8Wdvie0 ) 返回"types" : [ "route" ] Routes don't have ratings.路线没有评级。

Instead, use a place id of a business or other types of places that include ratings.相反,请使用包含评级的商家或其他类型地点的地点 ID。

Using the Place ID Finder and searching for Times Square returns a different place id: ChIJmQJIxlVYwokRLgeuocVOGVU .使用Place ID Finder并搜索Times Square会返回不同的地点 id: ChIJmQJIxlVYwokRLgeuocVOGVU

Doing a place details request with this place id:使用此地点 ID 执行地点详细信息请求:

https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJmQJIxlVYwokRLgeuocVOGVU&key=YOUR_API_KEY https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJmQJIxlVYwokRLgeuocVOGVU&key=YOUR_API_KEY

returns "types" : [ "tourist_attraction", "point_of_interest", "establishment" ] and "rating" : 4.7 .返回"types" : [ "tourist_attraction", "point_of_interest", "establishment" ]"rating" : 4.7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM