Howto Use SimpleSchema to fill GeoData in Database?


#1

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


#2

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.


#3

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\]'
}

#4

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).


#5

Maybe smth like this:

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

#6

Great! Works out of the box. Thanks heaps!