In my previous blog post I talked about how do we convert a place or zone into a bounding box and how do we efficiently store that inside a Django model. Right now I’m explaining how do we efficiently check if given latitude and longitude inside a bounding box. This is super helpful to check whether given location coordinates inside the zone or not. For example you may define a zone as San Francisco or New York and you have the location that needs to check if the location is really inside the geo region or not. Without further due let”s see some code in action.
from django.contrib.gis.geos import Point
point = Point(lat, lon)
Zone.objects.filter(geo__contains=point).all()
Above command will return all of the places that are in the geo boundary.