I try to calculate distance between two cities and I'm in big confusion because the results are wrong.

I have a model in geodjango like this:

class Address(geo_models.Model):
    coordinates = geo_models.PointField(srid=2180)
    objects = geo_models.GeoManager()

I create Address object using Lat anf Lng from Google Maps i this way

a = Address(coordinate = "POINT(%f %f)" % (lat, lng))

and then I calculate distance between Address object and another point (which lat and lng I have also from Google Maps)

coordinates = fromstr("POINT(%f %f)" % (lat, lng), srid=2180)
for a in addresses.distance(coordinates):

The calculation result is 25 km but I know that it is wrong. Right distance is around 18 km also Google Maps tells that it is 18 km.

Could someone tell me where I make a mistake?

EDIT 01:

I've added srid=2180 to model and to reference point and now the result is 0.237103265743 m


This is likely a spatial projection issue. From the GeoDjango (Django) documentation:

Distance calculations with spatial data is tricky because, unfortunately, the Earth is not flat. Some distance queries with fields in a geographic coordinate system may have to be expressed differently because of limitations in PostGIS. Please see the Selecting an SRID section in the GeoDjango Model API documentation for more details.

  • I've edited my question. Could you look at? – torm Jan 6 '15 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.