Improved distance to location code