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:
from geo import geomodel
Now, regarding your Location
model, in order to be able to execute a proximity_fetch
Query, your model should extend the provided model in geomodel called GeoModel
. Thus, you should have something like this:
class Location(ndb.Model, GeoModel):
....
Notice that GeoModel
currently uses the "old" GAE datastore layer db
and not ndb
that 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!
from geo import geotypes
They do a full example that can be found here: http://code.google.com/p/geomodel/source/browse/trunk/demos/pubschools/handlers/service.py http://code.google.com/p/geomodel/source/browse/#svn/trunk/demos/pubschools
results = PublicSchool.proximity_fetch(
base_query,
center, max_results=max_results, max_distance=max_distance)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.