alexreisner / geocoder

Complete Ruby geocoding solution.
http://www.rubygeocoder.com
MIT License
6.35k stars 1.19k forks source link

mysql type float rounds the value #70

Closed jspooner closed 13 years ago

jspooner commented 13 years ago

Do you have problems with mysql rounding your lat / lng float values?

alexreisner commented 13 years ago

Haven't had that, no. Can you give an example of a query where it's happening, and the result?

jspooner commented 13 years ago

Well it looks like it's caused by the float type because when you insert a number like 37.2928181 into your table you'll see it only saved 37.29.

This is a problem for my app that requires as much accuracy as possible. Another interesting thing is that this gem worked great with mysql and having lat/lng saved as a string. I used geocoding, reverse and the near named_scope, all worked well until until moving to Postgres.

How difficult would it be to store only integers?

alexreisner commented 13 years ago

MySQL is very lenient about data types and various other aspects of SQL and lets you do things that are not technically "correct." A lot of people have a bad experience when switching to Postgres but there's nothing wrong with it.

You'll get better performance with floats than strings, and if you need more precision you should look into using a higher precision data type. The double precision type (supported by both Postgres and MySQL) will give you 15 decimal digits which should be more than enough for coordinates on Earth.