Here is my model:
import datetime
from django.contrib.gis.db import models
class UserLocation(models.Model):
user = models.ForeignKey('auth.User')
coords = models.PointField()
date_created = models.DateTimeField(default=datetime.datetime.now)
objects = models.GeoManager()
@classmethod
def get_latest_location(cls, user):
return cls.objects.filter(user=user).latest()
class Meta:
get_latest_by = 'date_created'
When I try to query it like so:
coords = Point(x=34.4208305, y=-119.6981901) # in california
UserLocation.objects.distance(coords)
I get this error:
DatabaseError: Coordinate values are out of range [-180 -90, 180 90] for GEOGRAPHY type
CONTEXT: SQL function "st_distance_sphere" during inlining
Why is it wanting them in the range [-180 -90, 180 90]? That doesn't make any sense to me...
Considering a sphere (assuming the earth is round like a ball), using spherical coordinates (r, phi, tau), the given ranges are sufficient to identify every point on the sphere. For a detailed explanation of the coordinate system consult for instance Wikipedia at http://en.wikipedia.org/wiki/Spherical_coordinate_system.
If you have larger angles, you just fit them to the interval, e.g.
and similarly for tau.