How accurately should I store latitude and longitude?

后端 未结 7 533
囚心锁ツ
囚心锁ツ 2020-11-29 15:22

I was reading this question here:

What datatype to use when storing latitude and longitude data in SQL databases?

And it seems the general consensus is that

7条回答
  •  無奈伤痛
    2020-11-29 16:13

    The distance between each degree of latitude varies because of the shape of the earth and distance between each degree of longitude gets smaller as you get closer to the poles. So let's talk about the equator, where the distance between each degree is 110.574km for latitude and 111.320km for longitude.

    50ft is 0.01524km, so:

    • 0.01524 / 110.574 = 1/7255 of a degree of latitude
    • 0.01524 / 111.320 = 1/7304 of a degree of longitude

    You need four digits of scale, enough to go down to ten-thousandths of a degree, with a total of seven digits of precision.

    DECIMAL(7,4) should be plenty for your needs.

提交回复
热议问题