Home > database >  Which Django field should I use for longitude and latitude?
Which Django field should I use for longitude and latitude?

Time:07-21

I am saving longitude and latitude as FloatField. But when I tried to use them on JS in the array I figured out that FloatField separates with a comma instead of a dot as should be on latitude or longitude. So it acts like four different elements in js.

js:

map.on('load', () => {
'coordinates': [
    [{{tour.departure.city.longitude}},{{tour.departure.city.latitude}}],
    [{{tour.arrival.city.longitude}},{{tour.arrival.city.latitude}}],
    // it will be like  [ 23, 0534 , 42, 1534]
    // but should be like [ 23.0534 , 42.1534]
    ]
});

models.py

class Tour(models.Model):

    latitude = models.FloatField(blank=True, null=True, verbose_name=_("Latitude"))
    longitude= models.FloatField(blank=True, null=True, verbose_name=_("Longitude"))

I tried to save with dot but Django converted it to the comma.

CodePudding user response:

Check the DECIMAL_SEPARATOR setting. You may be inheriting a country-specific (or custom) formatting.

If this doesn't work, please update your question to include the relevant settings.

  • Related