ONYX
ONYX

Reputation: 5859

Laravel store latitude and longitude

I'm storing latitude and longitude and the problem I'm having is when it is being stored it gets rounded up, which isn't what I want. Otherwise those field values become incorrect when using the latitude and longitude on the map.

This is what I'm using:

$table->decimal('lat', 10, 8)->nullable();
$table->decimal('lng', 11, 8)->nullable();

this value -40.95560269999999 gets turned into this -40.9556027000 when I just want -40.9556026999

Upvotes: 13

Views: 16896

Answers (3)

Imran Hossain
Imran Hossain

Reputation: 11

The best way to use double in your migrations instead of decimals, is see below:

$table->decimal('long', 10, 7)->nullable();
$table->decimal('lat', 10, 7)->nullable();

Upvotes: -1

Donald Kagunila
Donald Kagunila

Reputation: 349

Use double in your migrations instead of decimals, see below

$table->double('lat')->nullable();
$table->double('lng')->nullable();

Upvotes: 14

Matius Nugroho Aryanto
Matius Nugroho Aryanto

Reputation: 901

your field's data type might be not decimal, make it sure that your field of lat long is decimal too

Upvotes: -3

Related Questions