2

我一直在尝试使用 node/express/backbone/mongoose 从表单中保存坐标 - 这可能与 MongoDB 本身有关

这是我的架构:

var MySchema = new mongoose.Schema({
 loc: {type:{type: String}, coordinates:[]}   
});

然后

var My = mongoose.model('My', MySchema);

var registerMy = function(loctype, longi, lati) {
var MyMy = new My({
  loc: {
    type:loctype,
    coordinates:[longi,lati]
        }
    });
 }

从 HTML 表单

<form>
<fieldset>
  <label>
   Loctype:
  <input type="text" name="loctype" />
  </label>
 <label>
Longitude:
<input type="number" name="longi" />
</label>
<label>
 Latitude:
<input type="number" name="lati" />
</label>
</fieldset>
<p>
 <input type="submit" value="Register Now"/>
</p>
</form>

然后我得到这个错误:

{ [MongoError: Can't extract geo keys from object, malformed geometry?:{ type: "Point", coordinates: [ "37.677163", "-1.696215" ] }] name: 'MongoError', err: 'Can\' t 从对象中提取地理键,格式错误的几何?:{类型:“点”,坐标:[“37.677163”,“-1.696215”]}',代码:16572,n:0,connectionId:200,ok:1}

4

1 回答 1

2

I had met with same problem, you might be trying to save location data as String Array, make sure that coordinates (longitude and latitude) is a Number array.

ie, the coordinates must be

[ 37.677163, -1.696215 ]

instead of

 [ "37.677163", "-1.696215" ]
于 2014-05-14T07:04:48.553 回答