are you recieving any errors? if not, place this on top of your script:
this will cause php to display all errors
i don't know the formula to calculate the distance across a sphere's surface by hard, so i don't know if you have an error in there, but i think not