4

我有以下模型:

class City(models.Model):
    name = models.CharField(null=False, blank=False, max_length=200)
    coordinates = models.PointField(null=False, blank=False)
    objects = models.GeoManager()

我正在尝试使用以下方法查找上述两个城市之间的距离:

city1=City.objects.get(name='New York')
city2=City.objects.get(name='Boston')
city1.coordinates.distance(city2)

但是得到以下信息:

Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/home/rok/apps/django-trunk/django/contrib/gis/geos/geometry.py", line 667, in distance
    raise TypeError('distance() works only on other GEOS Geometries.')
TypeError: distance() works only on other GEOS Geometries.

查看结构和数据,似乎还可以:

>>> city1.coordinates.coords
(40.714623,-74.006605)
>>> city2.coordinates.coords
(42.360024, -71.060168)

我究竟做错了什么?

4

0 回答 0