Google App Engine and Google Maps Proximity Search in Python
Due to the limitations of the GQL engine it has been suggested that people wanting to perform a proximity search should find someway around these limitations using the suggested geomodel. It might not be a very elegant or fast solution but is there anything to stop anyone using the algorithm from here:
SELECT id, ( 3959 * acos( cos( radians(lat_t) ) * cos( radians( la开发者_开发百科t ) ) * cos( radians( lng ) - radians(lng_t) )
+ sin( radians(lat_t) ) * sin( radians( lat ) ) ) ) AS distance
FROM Stores HAVING distance < 25
ORDER BY distance
as a simple way of computing the distance. I.e. we simply compute the distance by hand for each and every pair (lat, lng) and (lat_t, lng_t) by looping through each and every record in our datastore and thus getting the id that way of all records that are within our target distance without recourse to using the HAVING command? So to summarize we would do a simple GQL look up to get all records and loop through all pairs of lng/lat and compare with our target values.
http://code.google.com/apis/maps/articles/geospatial.html
Obviously that snippet is some flavour of SQL and not compatible with the Datastore's much simpler index based lookup.
If you mean you want to just fetch ALL your entities and perform the distance calculations in memory with python; then that is certainly possible, but you will be limited to doing this on a relatively small set of Entities or doing it in batches using Tasks.
Take a look at GeoModel which is designed for this very use case.
精彩评论