{"id":1366,"date":"2015-04-10T05:08:21","date_gmt":"2015-04-10T05:08:21","guid":{"rendered":"https:\/\/intelligentbee.com\/blog\/?p=1366"},"modified":"2025-05-06T13:48:14","modified_gmt":"2025-05-06T13:48:14","slug":"how-to-store-latitude-and-longitude-in-mysql","status":"publish","type":"post","link":"https:\/\/intelligentbee.com\/blog\/how-to-store-latitude-and-longitude-in-mysql\/","title":{"rendered":"How to Store Latitude and Longitude in MySQL"},"content":{"rendered":"<p>As we\u00a0know, 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\u00a0more\u00a0than centimeter-level accuracy.<!--more--><\/p>\n<p>This means we can use\u00a0a DECIMAL(10, 8) column to store latitude and a DECIMAL(11, 8) column to store longitude\u00a0in MySQL.<\/p>\n<h2>How to Store Latitude and Longitude in MySQL<\/h2>\n<p>In a\u00a0Symfony2\/Doctrine project we will use the following:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:php decode:true \">\/**\r\n * @ORM\\Column(type=\"decimal\", precision=10, scale=8)\r\n *\/\r\nprotected $lat;\r\n\r\n\/**\r\n * @ORM\\Column(type=\"decimal\", precision=11, scale=8)\r\n *\/\r\nprotected $lng;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As we\u00a0know, a latitude value can be between -90 and +90 degrees, whereas a longitude value can be between -180 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":1376,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[123,175,194,235],"yst_prominent_words":[476,944,1014],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/1366"}],"collection":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/comments?post=1366"}],"version-history":[{"count":3,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/1366\/revisions"}],"predecessor-version":[{"id":133274,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/1366\/revisions\/133274"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/media\/1376"}],"wp:attachment":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/media?parent=1366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/categories?post=1366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/tags?post=1366"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=1366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}