add calculate distance function
calculate distance function