地点详情 "place.opening_hours" 未返回所有标记的数据

Place detail "place.opening_hours" not returning data for all markers

我遇到一个问题,我从 Google 地图 JavaScript API 向 Places Libray 请求地点详情,但响应不是 return在 opening_hours 对象下读取所有标记的数据,只有其中一些。我已经检查过,这些标记确实标记了我的文本搜索中的实际位置和其他字段的 return 数据,我检查了这些地方的 Google Maps Native App returning "undefined" 对于 opening_hours 并且他们确实显示了开放和关闭时间。这里有一些代码可以更好地理解我的意思:

map.ts:

//Request for all places based on query search
var request = {
  location: this.myLocation,
  radius: '400',
  query: "McDonalds"
};

// Callback function for places
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
  for (let i = 0; i < results.length; i++) {
    let placeLoc = results[i].geometry.location;
    scopeObj.addMarker(results[i], placeLoc);
  }
}
};
let service = new google.maps.places.PlacesService(this.map);
service.textSearch(request, callback);

//Request for place details of each place, (this would loop through all place ids stored in an array
var request = {
  placeId: details.place_id,
  fields: ['name', 'formatted_address', 'formatted_phone_number', 'opening_hours',]
};

function callback(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
  console.log(place.opening_hourse); 
/* Returns Object object if data is found, 
   returns undefined otherwise, question is why 
   if status returns OK for all places that have 
   been marked with markers on the map? */
}
}

let service = new google.maps.places.PlacesService(this.map);
service.getDetails(request, callback);

使用我自己的 API 实现,我收到了来自不同地方响应的 opening_hours 信息。我已经省略了所有其他的绒毛,但这是我已经完成的地点详细信息请求,并且可以在许多企业上重复并仍然获得信息。

   {
   "html_attributions" : [],
   "result" : { 
         OMITTED
      "name" : "McDonald's",
      "opening_hours" : {
         "open_now" : true,
         "periods" : [
            {
               "close" : {
                  "day" : 0,
                  "time" : "1700"
               },
               "open" : {
                  "day" : 0,
                  "time" : "0800"
               }
            },
            {
               "close" : {
                  "day" : 1,
                  "time" : "2100"
               },
               "open" : {
                  "day" : 1,
                  "time" : "0800"
               }
            },
            {
               "close" : {
                  "day" : 2,
                  "time" : "2100"
               },
               "open" : {
                  "day" : 2,
                  "time" : "0800"
               }
            },
            {
               "close" : {
                  "day" : 3,
                  "time" : "2100"
               },
               "open" : {
                  "day" : 3,
                  "time" : "0800"
               }
            },
            {
               "close" : {
                  "day" : 4,
                  "time" : "2100"
               },
               "open" : {
                  "day" : 4,
                  "time" : "0800"
               }
            },
            {
               "close" : {
                  "day" : 5,
                  "time" : "2100"
               },
               "open" : {
                  "day" : 5,
                  "time" : "0800"
               }
            },
            {
               "close" : {
                  "day" : 6,
                  "time" : "1700"
               },
               "open" : {
                  "day" : 6,
                  "time" : "0800"
               }
            }
         ],
         "weekday_text" : [
            "Monday: 8:00 AM – 9:00 PM",
            "Tuesday: 8:00 AM – 9:00 PM",
            "Wednesday: 8:00 AM – 9:00 PM",
            "Thursday: 8:00 AM – 9:00 PM",
            "Friday: 8:00 AM – 9:00 PM",
            "Saturday: 8:00 AM – 5:00 PM",
            "Sunday: 8:00 AM – 5:00 PM"
         ]
      },
    OMITTED
   "status" : "OK"
}

我能看到你的实现和我的唯一区别是你在请求中指定了你想要的字段。

您可以尝试检索所有字段,而不是像您所做的那样专门请求字段:

var request = {
  placeId: details.place_id,
};

Fields 是一个可选参数,可能会给您带来问题。