GeoDjango with PostGIS - 距离计算错误

GeoDjango with PostGIS - distance calculation is wrong

我正在尝试将 GeoDjango 与 PostGIS 结合使用以测量距离,但我得到的结果相差 20%。

为了测试,我在海洋中选择了 2 个随机点:(40.607532, -72.829369) 和 (40.366040, -73.556856)。

为了获得预期的结果,我使用了两种不同的方法:

两者都给我相同的结果 41.71 英里。 Django 给我 50.49。

这是我的代码:

# models.py

from django.contrib.gis.db import models

class Location(models.Model):
    point = models.PointField(null=True)

然后从 django shell:

>>> from loc.models import Location
>>> from django.contrib.gis.geos import Point
>>> from django.contrib.gis.db.models.functions import Distance
>>> loc = Location(point=Point(40.366040, -73.556856, srid=4326))
>>> loc.save()
>>> pnt = Point(40.607532, -72.829369, srid=4326)
>>> qs = Location.objects.annotate(distance=Distance('point', pnt))
>>> qs[0].distance.mi
50.4954671273202

好的。我知道了。纬度和经度颠倒了。 Point 应该将 lng 作为第一个参数,将 lat 作为第二个参数。 Google 地图正好相反。

切换后,TADA...

>>> qs[0].distance.mi
41.7114806274482