0

I am wondering if it is better (faster, easier to manage!!!!, etc.) to store it as point such as GeomFromText('POINT(latitude longitude)') or to simply make two columns?

Also, if it is stored as a point, how would it be retrieved from the db? X(AsText(location)) and Y(AsText(location)) dont seem to be working for me.

George Mann
  • 85
  • 1
  • 4
  • possible duplicate of [What is the ideal data type to use when storing latitude / longitudes in a MySQL database?](http://stackoverflow.com/questions/159255/what-is-the-ideal-data-type-to-use-when-storing-latitude-longitudes-in-a-mysql) – Gajus Jun 15 '15 at 19:30

2 Answers2

1

Look at the problem the other way around and you will have your answer.

First think about how you would want to retrieve it, and what kind of queries you want to be able to do on that data. Then use the column format that's easiest for you to do that.

If want to retrieve latitude and longitude separately, use two columns.

Mat
  • 188,820
  • 38
  • 367
  • 383
0

I always use 2 columns Lat and Lng in my projects.

ysrb
  • 6,563
  • 2
  • 27
  • 29
  • @George: so you can query for a set of one or the other. – p.campbell Apr 08 '11 at 05:14
  • You need to store it so that it's reusable and in singular form or you might get headache later on. For example, finding a distance between 2 point need Lat and Lng . Furthermore, you might want to center the map and that requires Lat and Lng as separate fields – ysrb Apr 08 '11 at 05:16
  • and what field type? int, then multiply it by 10^15 or something to get rid of the decimal? – George Mann Apr 08 '11 at 05:20
  • Similar questions http://stackoverflow.com/questions/1196415/what-datatype-to-use-when-storing-latitude-and-longitude-data-in-sql-databases – ysrb Apr 08 '11 at 05:24
  • Another one http://stackoverflow.com/questions/551894/whats-the-best-way-to-store-co-ordinates-longitude-latitude-from-google-maps – ysrb Apr 08 '11 at 05:26
  • google maps return a lat like 52.449314140869674. you think its worth keeping those extra decimals? – George Mann Apr 08 '11 at 05:31
  • If you really want precision, then yes. Otherwise keeping up to 6 decimal place is suffice. It's suffice for me. – ysrb Apr 08 '11 at 05:33
  • and why do the other articles say float(10,6)? whats the difference and why the extra character? – George Mann Apr 08 '11 at 05:38
  • which article? From what i know float will add or remove the precision. Decimal won't. – ysrb Apr 08 '11 at 05:42
  • i meant the other questions mentioned above along with this google article http://code.google.com/apis/maps/articles/phpsqlajax.html – George Mann Apr 08 '11 at 05:44
  • Found one article for you. http://www.rustyrazorblade.com/2008/04/decimal-vs-float-in-mysql/ – ysrb Apr 08 '11 at 05:47
  • @GeorgeMann just a point about precision - given that the circumference of the earth is ~40,000,000m, 15 decimal places of latitude is sub-micrometre level accuracy - I suspect your GPS isn't really *that* accurate ;) – John Carter Feb 24 '12 at 02:32