【问题标题】:How to avoid OVER_QUERY_LIMIT nodejs如何避免 OVER_QUERY_LIMIT nodejs
【发布时间】:2018-11-01 00:16:04
【问题描述】:

每当我想在我的数据库中创建新位置时,我都会遇到这个错误,我试图实现 setTimeout() 来避免这种情况,但如果我做得正确,我不会感到沮丧。有什么建议吗?

router.post("/",middleware.isLoggedIn ,upload.single("image"),function(req, res){
 
    geocoder.geocode(req.body.place.location, function(err, data){
        while(status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT)
        {      
            setTimeout(3000);
        }  
        if ( err){   
            req.flash("error", err.message);
            console.log("error");  
            return res.redirect("back");
        }
        req.body.place.lat = data[0].latitude;
        req.body.place.lng = data[0].longitude;
    //cloudinary configuration    
    cloudinary.uploader.upload(req.file.path, function(result){
        // add cloudinary url for the image to the campground object under image property
        req.body.place.image = result.secure_url;
        // add author to campground
        req.body.place.author = {
            id: req.user._id,
            username: req.user.username
        };

        Place.create(req.body.place, function(err, newlyCreated){
            if(err){
                res.send(err);
            }else{
                res.redirect("/");
            }
        });
    });
  });
});

【问题讨论】:

  • google.maps.places.Autocomplete 也会有问题吗?

标签: javascript node.js google-maps geolocation


【解决方案1】:

From GOOGLE documentation concerning query limits

“收到状态码为 OVER_QUERY_LIMIT 的响应后,您的应用程序应确定超出了哪个使用限制。这可以通过暂停 2 秒并重新发送相同的请求来完成。如果状态码仍为 OVER_QUERY_LIMIT,则您的应用程序正在发送每天的请求太多。否则,您的应用每秒发送的请求太多。"

您的第一步需要是 2 秒超时来确定原因。如果每秒太多,请减少直到不再出现错误。

镉&

【讨论】:

  • 我搞错了,那个状态码是因为无效的api_key,还是谢谢你的回复:)
猜你喜欢
  • 2019-01-15
  • 2018-02-07
  • 1970-01-01
  • 2021-07-23
  • 2017-08-18
  • 1970-01-01
  • 2013-12-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多