Posts Tagged ‘doctrine’

Fixing Doctrine’s Geographical template precision

Tuesday, April 27th, 2010

(Note that this blog post is about Doctrine 1.2. At the time of this minor update—Nov 16, 2010—I can’t seem to actually FIND a Geographical behavior in Doctrine 2. So, if you’re using Doctrine 2, this post probably isn’t for you. It sucks, I know, this behavior was friggin’ handy.)

Doctrine, an ORM library, has a convenient little behavior that you can attach to your tables to give them awesome superpowers of geolocation. It’s the Geographical template, and it resides in Doctrine/Template/Geographical.php. What it does is add two fields to your table: Latitude and Longitude, and extends your model with the ability to discern distances between any two of these locations.

That’s all well and good, except that as of 1.2.2, Doctrine’s default precision for a floating point field is 2. That doesn’t allow for very accurate geolocation, as it truncates something like “+33.544622″ down to “33.54″. Not good.

(more…)