在Django中使用哪个模型字段存储经度和纬度值? [英] Which Model Field to use in Django to store longitude and latitude values?

查看:266
本文介绍了在Django中使用哪个模型字段存储经度和纬度值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用经度和纬度存储用户位置,目前这是来自Google地图,但是我将使用GeoDango和一些点来计算点与点之间的距离。

I want to store my users location using longitude and latitude, at the moment this comes from Google Maps, but I will be using GeoDango and some point to work out distances between to points also.

但是,我的第一个困惑是应该使用Django中的哪个字段存储经度和纬度值?我收到的信息有冲突。

However, my first confusion is which field in Django I should be using to store the longitude and latitude values? The information I'm getting is conflicting.

官方文档使用 FloatField
https://docs.djangoproject.com/en/dev/ref/contrib/gis/tutorial/#geographic-models

lon = models.FloatField()
lat = models.FloatField()

几乎所有关于stackoverflow的答案都显示 DecimalField

Where almost every answer on stackoverflow shows a DecimalField

long = models.DecimalField(max_digits=8, decimal_places=3)
lat = models.DecimalField(max_digits=8, decimal_places=3)

那我应该用什么?

推荐答案

浮点数通常是一个近似值,请参见此处的一些简单示例。将模型修改为 DecimalField(max_digits = 9,decimal_places = 6)可能会得到很好的结果,因为小数在坐标中非常重要,但基本上使用6以上毫无意义。

Float is generally an approximation, see here for some simple examples. You could get very nice results modifying your model to something like DecimalField(max_digits=9, decimal_places=6), since decimals are very important in coordinates but using more than 6 is basically meaningless.

这篇关于在Django中使用哪个模型字段存储经度和纬度值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆