LiveWhale Push Updated
August 08, 2011
By David McKelvey
Today I completed a significant update to LiveWhale Push, our open source push notifications module for LiveWhale, to account for the addition of LiveWhale Places last week. LiveWhale Push now allows subscribers to use two new parameters for filtering updates based on location: place_id and radius.
When place_id is specified, the news story, event or blurb must be located within the radius (in miles up to 10) of the place. And, radius can be zero, to keep updates limited to those geo-tagged with just that place.
Adapting LiveWhale Push did take a good bit of work for various reasons, but among them was the calculation of the radius for each subscription each time someone updates their content. The equations for calculating distance based on the latitude and longitude are somewhat complex and at first I opted to use MySQL’s built in spatial functions normally used for GIS.
However, there was a downside as those functions were based on the assumption of flat cartesian space, and not distance wrapped around a curved globe. I did some approximation to account for this, but MySQL also left me with the usable distance in degrees radians, which was not helpful, so in the end I switched to using an equation that allowed me to keep my distances in miles.
There’s a number of equations that will help you with this like the haversine or equirectangular approximation — to varying degrees of accuracy. In the end I chose the spherical law of cosines as I was limiting radius to ten miles and LiveWhale UI encourages more than a few meters distance between places. MySQL is still doing all the calculations, but it keeps everything in location-relevant distance.