visit our site

How to Store Latitude and Longitude in MySQL

In PHP and Symfony

by Dragos Holban on April 10, 2015

As we know, a latitude value can be between -90 and +90 degrees, whereas a longitude value can be between -180 and +180 degrees. To get accuracy to within a meter, only six decimal places are needed, which is sufficient for most cases. But you can go even further by using eight places which will give you more than centimeter-level accuracy.

This means we can use a DECIMAL(10, 8) column to store latitude and a DECIMAL(11, 8) column to store longitude in MySQL.

In a Symfony2/Doctrine project we will use the following:

 

 

One Reply to “How to Store Latitude and Longitude in MySQL”

Leave a Reply

Your email address will not be published. Required fields are marked *

+1
Share
Tweet
Share
Stumble
Pin