2

I want to store a value of lng and lat in database but I am little confused that which data type I should use to store and how much max and min length is required for storing lng and lat values.

0

1 Answer 1

2

This question has been discussed before, but notably absent from that discussion is any reference to MySQL's GIS data types. It's possible that POINT (or one of the other geometry data types) would do an excellent job here as well.

The previous discussion concluded that using DECIMAL(10, 8) for latitude and DECIMAL(11, 8) for longitude would be appropriate.

5
  • 1
    That precision would give about 1mm resolution. This is excessive for most uses. Apr 14, 2018 at 17:58
  • @BillKarwin Which data type would, POINT? I'm still a fan of using the native data types designed for a particular use, even if the resolution is better than needed, that way we can let MySQL handle any math involved. Aside from the wasted storage overhead, is there any other reason not to use the GIS data type here? Apr 14, 2018 at 18:03
  • I'd want to know how the app queries the lat/long data. For example, it's not clear how JDBC would map POINT into java types. Could be easier to use DECIMAL. Apr 14, 2018 at 18:09
  • Also MySQL didn't support POINT in InnoDB until version 5.6, and didn't support spatial indexes on GIS types until version 5.7. If you're stuck using an old version, I'd prefer to use DECIMAL than to use MyISAM tables. Apr 14, 2018 at 18:11
  • I added more choices here
    – Rick James
    May 2, 2018 at 3:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.