mercredi 21 janvier 2015

latitude and longitude query in django


Vote count:

0




I need a quick fix for simple spatial search in django. My main problem right now is that floats cannot be negative and I'm not sure how to overcome this.


Here is what my model looks like



class CustomEvent(models.Model):
lat = models.FloatField(blank=True, null=True)
lng = models.FloatField(blank=True, null=True)


and this is my really bad query but I need to get it working really quick



lat = float(request.GET['lat'])
lng = float(request.GET['lng'])

min_lat = lat - 1 # You have to calculate this offsets based on the user location.
max_lat = lat + 1 # Because the distance of one degree varies over the planet.
min_lng = lng - 1
max_lng = lng + 1

custom_events_raw = CustomEvent.objects.filter(lat__gt=min_lat, lat__lt=max_lat, lng__gt=min_lng, lng__lt=max_lng)


I know I should do spatial queries with geodjango or something but this just needs to look like its working for now.



asked 1 min ago







latitude and longitude query in django

Aucun commentaire:

Enregistrer un commentaire