public double GetDistance(int docid, double centerLat, double centerLng, double lat, double lng) { // check to see if we have distances // if not calculate the distance if (_distances == null) { return(DistanceUtils.GetInstance().GetDistanceMi(centerLat, centerLng, lat, lng)); } // check to see if the doc id has a cached distance double docd; _distances.TryGetValue(docid, out docd); if (docd > 0) { return(docd); } //check to see if we have a precision code // and if another lat/long has been calculated at // that rounded location if (_precision.HasValue) { double xLat = GetPrecision(lat, _precision); double xLng = GetPrecision(lng, _precision); String k = xLat + "," + xLng; Double d; _distanceLookupCache.TryGetValue(k, out d); if (d > 0) { return(d); } } //all else fails calculate the distances return(DistanceUtils.GetInstance().GetDistanceMi(centerLat, centerLng, lat, lng)); }