Search code examples
djangopostgresqlgeolocationpostgisgeodjango

geoDjango changing longitude automatically


i'm making a location base web application and for this i'm using geoDjango and postgis . the problem is whenever i try to store some location(latitude/longitude) around dhaka,bangladesh ,it automatically change the longitude. after doing some debugging i found that, whenever longitude cross 90.00, geoDjango save longitude as 89.something .

My model:

from django.db import models
from django.contrib.gis.db import models as locationModels

class Advertise(models.Model):
        house_name = models.CharField(max_length=100, null=True)
        geoLocation = locationModels.PointField(geography=True, null=True)

Example:

from django.contrib.gis.geos import Point
lat, lng = 23.724609, 88.882694
pnt = Point(lat, lng)
add = models.Advertise(geoLocation=pnt,house_name='test1')
add.save()

add = models.Advertise.objects.filter(house_name='test1')

Output of add[0].geoLocation.y is 88.882694

if i change the value of lat,lng to 23.777976, 90.010106, the Output of add[0].geoLocation.y became 89.989894, but it should be 90.010106

can anyone tell me where i'm doing wrong ?


Solution

  • You are swapping latitudes and longitudes. You must specify the longitude first (x), then the latitude (y).

    Unfortunately, instead of throwing an error, PostGIS will try to interpret the out of bound value, like moving on the other side of earth or moving "back" from the pole if the latitude is > 90 degrees.