Mongoengine geospatial search

geolocation, geospatial, mongodb, mongoengine, pymongo

Solution

Can you post what you are trying to do??

Point data must be stored in a field with key

`"loc":{"lon":51.10682735591432, "lat":-114.11773681640625}` or

`loc: [22.23432, 21.23212]`

With mongoengine there is support for a geopoint field

Class Location:
  point = GeoPointField()

new_location = Location(point=[21.1232,23.23432])
new_location.save()

something like above should work.

class GeoPointField(db_field=None, name=None, required=False, default=None, unique=False, unique_with=None, primary_key=False, validation=None, choices=None, verbose_name=None, help_text=None):

A list storing a latitude and longitude.

New in version 0.4.

http://mongoengine-odm.readthedocs.org/en/latest/apireference.html#mongoengine.GeoPointField

Problem

Has anyone used geospatial searching with mongengine? I can't seem to get it to work! What is the format of the data that has to go in the GeoPointField? How should i format it? I can't find anything about the formating in the documentation!

Original source