【发布时间】: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