What MySQL data type should be used for Latitude/Longitude with 8 decimal places?
MySQL supports Spatial data types and Point
is a single-value type which can be used. Example:
CREATE TABLE `buildings` ( `coordinate` POINT NOT NULL, /* Even from v5.7.5 you can define an index for it */ SPATIAL INDEX `SPATIAL` (`coordinate`)) ENGINE=InnoDB;/* then for insertion you can */INSERT INTO `buildings` (`coordinate`) VALUES(POINT(40.71727401 -74.00898606));
in laravel used decimal column type for migration
$table->decimal('latitude', 10, 8);$table->decimal('longitude', 11, 8);
for more information see available column type
Additionally, you will see that float
values are rounded.
// e.g: given values 41.0473112,29.0077011float(11,7) | decimal(11,7)---------------------------41.0473099 | 41.047311229.0077019 | 29.0077011