Reputation: 612
Hello, I am using the google map api and google places api, and I have this issue in large quantities. In fact, with each call to google places api:
"open_now is deprecated as of November 2019 and will be turned off in November 2020. Use the isOpen() function from a PlacesService.getDetails()"
I read the doc and did some research but I was told that I should not use open_now.
I don't use open_now or isOpen() in my project
Anyone to solve this issue ?
const map = store.state.map;
const google = store.state.google;
const service = new google.maps.places.PlacesService(map);
const center = map.getCenter();
const nearbySearchRequest = {
location: center,
radius: 650,
types: ["restaurant"]
};
function nearbySearchCallback(results, status) {
const API_KEY = firebaseConfig.apiKey;
if (status == 'OK') {
let restaurants = results;
restaurants.forEach((restaurant, i) => {
// For each restaurant, we get the reviews
function getDetailsCallback(reviews) {
restaurant.reviews = reviews;
}
const getDetailsRequest = {
fields: ["reviews"],
placeId: restaurant.place_id
};
service.getDetails(getDetailsRequest, getDetailsCallback);
//For each restaurant, we get the image
const lat = restaurant.geometry.location.lat();
const lng = restaurant.geometry.location.lng();
restaurant.img = `https://maps.googleapis.com/maps/api/streetview?size=150x150&location=${lat},${lng}&key=${API_KEY}`;
});
store.commit("UPDATE_RESTAU", restaurants);
setMarkers();
}
}
service.nearbySearch(nearbySearchRequest, nearbySearchCallback);
Upvotes: 0
Views: 1129
Reputation: 1034
I never used the “open_now()” function. I created some invisible text boxes to hold an Open or Closed status based on the current date/time. Then I added some javascript to populate those text boxes based on date/time, holiday and weekends. Finally, I added a function to my object array, in this case, airports, to get the value from the textboxes for the Open/Closed status.
I think this could be better explained by showing you a sample. Here’s a link to my CodePen where I placed it. Sometimes it works fine on CodePen and sometimes it doesn’t. But, it always works great if you just download the project and run it from your computer. Or, just copy/paste the “html, css and javascript” from the pen.
https://codepen.io/pailwriter/pen/MWyevGO
Please replace the API key with your own.
You can break out the 3 sections on the javascript page into 3 different js pages. Just take note of the order their in and in the "head" section of your html page, call them in that order.
Here's a quick look at the date/time JavaScript to work with.
var today = new Date();
var dateNow = today.getFullYear()+','+(today.getMonth()+1)+','+today.getDate();
var holidays = (
'2020,1,1',
'2020,1,20',
'2020,2,17',
'2020,5,25',
'2020,7,3',
'2020,9,7',
'2020,10,12',
'2020,11,11',
'2020,11,26',
'2020,12,25'
);
var d = new Date();
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var n = weekday[d.getDay()];
// Start Clock - H:m only
setInterval(function(){
var tdate = new Date();
var tformat = [
("0" + tdate.getHours()).substr(-2)
, ("0" + tdate.getMinutes()).substr(-2)
].join(":");
//Based on current date/time, populate the "invisible" text boxes on the index.html page. *********************************
// Open/Closed status for Monday through Friday only
if (tformat > '09:00' && tformat < '17:00' && n != "Sunday" && n != "Saturday" && holidays != dateNow) {
document.getElementById("Shift1").innerHTML = "Open";
document.getElementById("Shift1").value = "Open";
}
else {
document.getElementById("Shift1").innerHTML = "Closed";
document.getElementById("Shift1").value = "Closed";
}
// Open/Closed status for Monday - Saturday
if (n == "Saturday" && tformat > '08:00' && tformat < '17:00' && holidays != dateNow || n != "Saturday" && n != "Sunday" && holidays != dateNow && tformat > '09:00' && tformat < '13:00') {
document.getElementById("Shift2").innerHTML = "Open";
document.getElementById("Shift2").value = "Open";
}
else {
document.getElementById("Shift2").innerHTML = "Closed";
document.getElementById("Shift2").value = "Closed";
}
// Main Branch Hours Only ********************************* End *****************************************************
// This is the closing tag for all the time/date options above. Do not remove.
}, 100);
Upvotes: 0