1

I am trying to store the lat, lng in my model. I have defined my model as

attributes: {
    point: {type: 'json'}
}  

And i am passing the coordinates simply as [x ,y]. But it is storing the point as NULL. So please, if anyone knows how to deal with it, please help me. I have no idea how to do this.

live_alone
  • 159
  • 1
  • 11
  • Are you converting the array to a JSON string? Or are you trying to pass the array directly? If you're passing it directly you'll want `type: 'array'` – Ben Fortune Jul 28 '14 at 11:15
  • i am passing the whole array – live_alone Jul 28 '14 at 11:46
  • Then the type is array, not json. – Ben Fortune Jul 28 '14 at 11:51
  • @BenFortune, type `json` will work for both. `array` will just validate it as an actual array. @live_alone, can you show the code where you're saving the model instance? – sgress454 Jul 28 '14 at 20:36
  • @ScottGress , i am able to store the points now, but there is other issue. On using native query for geoNear, it throws me an error "no geo indices for geoNear". So if you know anything about it, please let me know...? – live_alone Jul 29 '14 at 07:25

2 Answers2

0

I tried to do something similar to this using the more funky field types but found that breaking it down to primitive types worked better.

module.exports = {

  attributes: {

    speed: {
      type: 'string'
    },

    heading: {
      type: 'string'
    },

    altitude: {
      type: 'string'
    },

    altitudeAccuracy: {
      type: 'string'
    },

    longitude: {
      type: 'float',
      required: true
    },

    latitude: {
      type: 'float',
      required: true
    },

    accuracy: {
      type: 'string'
    }

  }

};

here is the complete object for storing geo data.

simondelliott
  • 283
  • 1
  • 3
  • 7
0

When you have the geolocation as JSON attribute, you can store the location like so: { "type": "Point", "coordinates": [ 7.88, 47.78 ] } }

When you then create an 2dsphere index in MongoDB on this field

db.collection.createIndex({ geolocation: "2dsphere" })

you can make use of MongoDBs spatial queries.