Howto Use SimpleSchema to fill GeoData in Database?

Hi there,

I am having troubles using SimpleSchema to define a location object and fill in gMaps event data (event.latLng , or event.latLng.lat() )
Also I want to use MongoDbs near function to search the data.

similar to http://stackoverflow.com/questions/24492333/meteor-simple-schema-for-mongo-geo-location-data

Does anyone have a working snippet of this task?
Thanks a lot
java99

I do it with the following code:
Places = new SimpleSchema({
ā€˜locā€™ : {
type: [Number],
decimal: true,
index: ā€œ2dsphereā€,
optional: false,
label : ā€œLong/Lat Coordsā€,
minCount: 2,
maxCount: 2
}
);

Dont forget to create an 2dsphere index in your MongoDb collection.

Iā€™m using this one:

location: {
    type: Object,
    index: '2dsphere',
    label: 'MongoDB spesific coordinates field'
},
'location.type': {
    type: String,
    allowedValues: ['Point'],
    label: 'Typeof coordinates - Point'
},
'location.coordinates': {
    type: [Number],
    decimal: true,
    label: 'Array of coordinates in MongoDB style \[Lng, Lat\]'
}
2 Likes

Thanks guys!

How would you in both cases set the values from a command like

Markers.insert({ user: Session.get(ā€˜userā€™), loc.???: event.latLng.lat()});

event.latLng is what I get from the mapClickEvent (gmaps v3).
My meteor does not even compile when I do something like loc. (no extension allowed). So I must pass a complete object and in the correct order (long/lat for mongo).

Maybe smth like this:

  Markers.insert({ user: Session.get('user'), location: {"type": "Point", "coordinates": [event.latLng.lng(), event.latLng.lat()]}});
1 Like

Great! Works out of the box. Thanks heaps!