Google Maps API 向我发送旧数据

问题描述 投票:0回答:1

我为客户制作了一个小部件,通过地点 ID 从 google API 中提取地点信息并将其输出到他们的网站上,这样他们只需在 Google 个人资料中管理时间即可。它已连接,一切看起来都很好,但现在他们已经更改了工作时间(本周周三和周四关闭),编辑不再通过 API 进行。 Google 仍在向我发送旧信息。

我正在从 opening_hours 获取 weekday_text...

function initMap() {
  const map = new google.maps.Map(document.getElementById("hours-map"), {
    center: { lat: 29.9514775 , lng: -90.100022},
    zoom: 15,
  });
  const request = {
    placeId: "ChIJg3BoLpalIIYRToYZ5yCFQYI",
    fields: ["name", "formatted_address", "place_id", "geometry", "opening_hours"],
  };
  const infowindow = new google.maps.InfoWindow();
  const service = new google.maps.places.PlacesService(map);

  service.getDetails(request, (place, status) => {
    if (
      status === google.maps.places.PlacesServiceStatus.OK &&
      place &&
      place.geometry &&
      place.geometry.location
    ) {
      const marker = new google.maps.Marker({
        map,
        position: place.geometry.location,
      });
const info = document.getElementById("hours-info");
var hours= place.opening_hours;
info.innerHTML = place.opening_hours.weekday_text[0]+ '<br>' +
         place.opening_hours.weekday_text[1] + '<br>' +
         place.opening_hours.weekday_text[2] + '<br>' +
         place.opening_hours.weekday_text[3] + '<br>' +
         place.opening_hours.weekday_text[4] + '<br>' +
         place.opening_hours.weekday_text[5] + '<br>' +
         place.opening_hours.weekday_text[6] + '<br>';
      google.maps.event.addListener(marker, "click", () => {
        const content = document.createElement("div");
        const nameElement = document.createElement("h2");

        nameElement.textContent = place.name;
        content.appendChild(nameElement);
        const placeAddressElement = document.createElement("p");

        placeAddressElement.textContent = place.formatted_address;
        content.appendChild(placeAddressElement);
        infowindow.setContent(content);
        infowindow.open(map, marker);
      });
    }
  });
}
google-maps google-business-profile-api
1个回答
0
投票

也许这对其他人会有帮助:我发现我只是在正常工作时间,而我的客户已经更新了他们的特殊工作时间。看起来我需要一个不同的 API 来获取这些...请参阅 无法从 Google Places API 获取特殊开放时间

© www.soinside.com 2019 - 2024. All rights reserved.