Specify the distance calculation for latitude and longitude of two-point location
1 #Coding=utf-82 3 fromMathImport*4 5 #input lat_a latitude A6 #input lng_a Longitude A7 #input Lat_b latitude B8 #input Lng_b Longitude B9 #output distance distance (km)Ten defcalcdistance (lat_a, Lng_a, Lat_b, Lng_b): OneRA = 6378.140#Equatorial radius (km) ARB = 6356.755#Polar radius (km) -Flatten = (RA-RB)/RA#Earth Flat Rate -Rad_lat_a =radians (lat_a) theRad_lng_a =radians (lng_a) -Rad_lat_b =radians (lat_b) -Rad_lng_b =radians (Lng_b) -PA = Atan (Rb/ra *Tan (rad_lat_a)) +PB = Atan (Rb/ra *Tan (rad_lat_b)) -xx = ACOs (sin (PA) * sin (pb) + cos (PA) * cos (PB) * cos (RAD_LNG_A-rad_lng_b)) +C1 = (sin (xx)-XX) * (sin (pA) + sin (pB)) * * * 2/COS (XX/2) * * 2 AC2 = (sin (xx) + xx) * (sin (pA)-sin (pB)) * * * 2/sin (XX/2) * * 2 atDr = Flatten/8 * (C1-C2) -Distance = RA * (xx +DR) - returnDistance - -lat_a=32.060255; lng_a=118.796877#Nanjing -lat_b=39.904211; lng_b=116.407395#Beijing inDistance=calcdistance (Lat_a,lng_a,lat_b,lng_b) - Print('(lat_a, lng_a) = ({0:10.3f},{1:10.3f})'. Format (lat_a,lng_a)) to Print('(Lat_b, Lng_b) = ({0:10.3f},{1:10.3f})'. Format (lat_b,lng_b)) + Print('distance={0:10.3f} miles'. Format (distance))
Execution Result:
(lat_a, lng_a) = ( 32.060, 118.797) (Lat_b, lng_b) = ( 39.904, 116.407) Distance= 896.533 km
"Python learning" specifies the distance calculation for two-point geographic latitude and longitude