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

前端 未结 21 2405
梦如初夏
梦如初夏 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:56

    Use MySQL's spatial extensions with GIS.

    0 讨论(0)
  • 2020-11-22 09:56

    depending on you application, i suggest using FLOAT(9,6)

    spatial keys will give you more features, but in by production benchmarks the floats are much faster than the spatial keys. (0,01 VS 0,001 in AVG)

    0 讨论(0)
  • 2020-11-22 09:57

    I suggest you use Float datatype for SQL Server.

    0 讨论(0)
  • 2020-11-22 09:58

    MySQL uses double for all floats ... So use type double. Using float will lead to unpredictable rounded values in most situations

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-11-22 10:00

    The ideal datatype for storing Lat Long values is decimal(9,6)

    This is at approximately 10cm precision, whilst only using 5 bytes of storage.

    e.g. CAST(123.456789 as decimal(9,6))

    0 讨论(0)
提交回复
热议问题