GeoDjango,来自 Google 地图的坐标在使用 PointField 的传单上绘制错误

GeoDjango, Cordinates from Google maps are getting plotted wrong on leaflet using PointField

请帮我解决这个问题。

class RecievingImages(models.Model):
    """Original and Masked Images"""
    name          = models.CharField(max_length = 100, unique = True, primary_key=True)
    cordinate_X   = models.FloatField()
    cordinate_Y   = models.FloatField()
    point         = models.PointField(srid=4326, geography=True, default='POINT(0.0 0.0)')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = 'Image Mapping'



我有从 google 地图 API 得到的坐标 这里的例子

cordinate_X : 21.2166277
cordinate_Y : 72.7763859

从技术上讲,这些坐标是印度古吉拉特邦的坐标 actual link of the coordinates

现在要绘制在传单上,我参考这个 link 将其转换为点场

from django.contrib.gis.geos import Point

for l in RecievingImages.objects.all():
...     l.point = Point(x=l.cordinate_X, y=l.cordinate_Y, srid=4326)
...     l.save()

现在,当我返回 Django 管理页面时,它在 Sea 的某处错误地标记了坐标

感谢您的宝贵时间。

此致


更新

经过大量谷歌搜索后,我发现可能存在使用 srid 的问题,即 google 地图可能正在使用“3587”,我使用过“4326” 我试图更改此设置,但出现错误。

    raise NotSupportedError('PostGIS only supports geography columns with an SRID of 4326.')
django.db.utils.NotSupportedError: PostGIS only supports geography columns with an SRID of 4326.

我用过的数据库是PostGIS

我想你的坐标调换了。 X是经度,Y是纬度。

您的 link 在此处显示坐标: 21°12'59.9"N 72°46'35.0"东经。 Google 纬度优先。

试试这个:

cordinate_X : 72.7763859
cordinate_Y : 21.2166277