2017-04-17 214 views
0

我正在研究nodejs后端的地理位置搜索。而mongodb是数据库。为了做到这一点,我从前端获得价值。我正在使用地图getbound来获取视口数据。以下是一些包含经度和纬度的变量。如何创建坐标数组?

var topLeftLong = parseFloat(req.body.topLeftLong); 
    var topLeftLat = parseFloat(req.body.topLeftLat); 

    var topRightLong = parseFloat(req.body.topRightLong); 
    var topRightLat = parseFloat(req.body.topRightLat); 

    var bottomRightLong = parseFloat(req.body.bottomRightLong); 
    var bottomRightLat = parseFloat(req.body.bottomRightLat); 

    var bottomLeftLong = parseFloat(req.body.bottomLeftLong); 
    var bottomLeftLat = parseFloat(req.body.bottomLeftLat); 

虽然我得到这些数据,我想把经度和纬度放在一个数组中。但是每当我尝试在数组中推送数据时,我都会得到下面的错误。

This is error from mongodb (may be)

回答

0

好像错误的数据类型是罪魁祸首。在你的代码中,如果你使用了cast,例如(int)string-var,那么它可能是由于这个错误。数据类型很重要。不匹配的数据类型会导致错误。