公式推导比较简单,直接上代码:

#!/usr/bin/env python
# -*- coding=utf-8 -*-

'''
经纬度求球面距离
file: R.py
ref:
  http://blog.csdn.net/csfreebird/article/details/6820823
'''

import math

lat1 = 40.0028
long1 = 126.77654
lat2 = 40.010092
long2 = 126.58763
R = 6378.137*1000

def func1(lat00,long00,lat11,long11):
    a = (lat00-lat11)*math.pi/180
    b = (long00-long11)*math.pi/180

    a1 = math.sin(a)
    b1 = math.sin(b)

    if(a==b and a==math.pi):
        y = 2*math.pi*R
    else:
        y = 2*R*math.asin(pow((a1*a1+b1*b1),0.5)*0.5)
    return y
    
def func2(lat00,long00,lat11,long11):
    a00 = lat00*math.pi/180
    a11 = lat11*math.pi/180
    a = a00-a11
    b = (long00-long11)*math.pi/180

    y = 2 * R * math.asin(math.sqrt(pow(math.sin(a*0.5),2) + math.cos(a00)*math.cos(a11)*pow(math.sin(b*0.5),2)));
    return y;

y = func1(lat1,long1,lat2,long2)    
print y
y = func2(lat1,long1,lat2,long2)
print y</pre>