Fixed a bug in getDistance function