What is the ideal data type to use when storing latitude / longitude in a MySQL database?

前端 未结 21 2904
梦如初夏
梦如初夏 2020-11-22 09:40

Bearing in mind that I\'ll be performing calculations on lat / long pairs, what datatype is best suited for use with a MySQL database?

21条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 09:59

    1. Latitudes range from -90 to +90 (degrees), so DECIMAL(10, 8) is ok for that

    2. longitudes range from -180 to +180 (degrees) so you need DECIMAL(11, 8).

    Note: The first number is the total number of digits stored, and the second is the number after the decimal point.

    In short: lat DECIMAL(10, 8) NOT NULL, lng DECIMAL(11, 8) NOT NULL

提交回复
热议问题