from:http://blog.csdn.net/zhuqiuhui/article/details/53180395
1. Find the azimuth of two latitude and longitude points, P0 (LatA, Lona), P1 (LATB, lonb) (many blogs do not write very well, summarize here)
def getdegree (LatA, Lona, LATB, lonb): "" " Args: Point P1 (LatA, Lona) point P2 (LATB, lonb) Returns : bearing between the "GPS points, default:the basis of heading direction is" "" radlata = Radia NS (LatA) Radlona = radians (lona) RADLATB = radians (LATB) radlonb = radians (lonb) Dlon = radlonb- Radlona y = sin (dlon) * cos (RADLATB) x = cos (radlata) * sin (RADLATB)-Sin (radlata) * cos (RADLATB) * cos (dlon)
brng = degrees (atan2 (y, x)) brng = (brng +)% return brng
2. Find the distance function of two latitude and longitude points: P0 (LatA, Lona), P1 (LATB, LONB)
def getdistance (LatA, Lona, LATB, lonb): ra = 6378140 # radius of equator:meter RB = 6356755 # radius of Polar:meter flatten = (RA-RB)/RA # Partial rate of the earth # change angle to radians Radlata = Radi Ans (latA) Radlona = radians (lona) RADLATB = radians (LATB) radlonb = radians (lonb) PA = Atan (Rb/ra * t An (radlata)) PB = Atan (Rb/ra * TAN (RADLATB)) x = ACOs (sin (PA) * sin (pb) + cos (PA) * cos (PB) * cos (radlona-ra DLONB) C1 = (sin (x)-X) * (Sin (PA) + sin (pb)) **2/cos (X/2) **2 c2 = (sin (x) + x) * (Sin (PA)-sin (pb)) **2/ Sin (X/2) **2 dr = Flatten/8 * (c1-c2) distance = RA * (x + dr) return distance
Python realizes the distance and azimuth between two latitude and longitude points