I am trying to do a proximity_fetch with the GeoModel class for Google App Engine. The entity I want to use it for is ndb and I am not sure what I need to download and import and what I can just import from google in my python code. The websites seem to be a little outdated and I was wondering if anyone had more pertinant information. This is what I have so far and it is telling me that Location has no attribute proximity_fetch, which I know but I am not sure how I should define it in the Location(ndb.Model) class.
g = geocoders.Google()
place, (lat, lng) = g.geocode(inputlocation, exactly_one=False)
bound = 20
upper = lat + bound
lower = lat - bound
left = lng + bound
right = lng - bound
locations = []
if lat and lng:
locations = Location.proximity_fetch(
Location.query(),
geotypes.Point(lat, lng),
max_results=50,
max_distance=500000)
Also when I try to import geomodel and geotype which seem pretty vital for this it gives me an import error and I am not sure where to get them from.
Any help or examples would be greatly appreciated!
You should first checkout the latest code from the SVN repository. You can find the information about this at http://code.google.com/p/geomodel/source/checkout
After you have the code locally on your machine, inside the main directory there is a directory called
geo. You should copy this directory into your GAE project. Then in your code, you import what you need from this package. For example:Now, regarding your
Locationmodel, in order to be able to execute aproximity_fetchQuery, your model should extend the provided model in geomodel calledGeoModel. Thus, you should have something like this:Notice that
GeoModelcurrently uses the “old” GAE datastore layerdband notndbthat you are using in your code. However, it shouldn’t cause any trouble.For more information on how to use geomodel, you should also take a look at the demos that also exist in the code you got from SVN. You can find them in the demos directory.
Hope this helps!