The problem we are encountering now is: After getting the data input by the user, how to combine the formula based on the user's data to calculate the distance and return the result.
Currently there are two files, one is py
One is html.
I have run this formula in anaconda-jupyter and can get the distance. But jupyter runs because it has been run above, so there is data to run.
However, now I don’t know where to fill in and what to fill in so that the airport data can be entered into the formula, and the distance result can be returned to .
The following is part of the ppy code
def searchcities() -> 'html':
airportone = request.form['user_airportone']
airporttwo = request.form['user_airporttwo']
distanceone = calcDistance['distance']
return render_template('results.html',
the_title = '以下是您选取的机场:',
the_airportone = airportone,
the_airporttwo = airporttwo,
the_distance = distanceone
)
The following is part of the html code
from math import radians, cos, sin, atan, acos,tan
def calcDistance(a1,a2):
ra = 6378.140 # 赤道半径 (km)
rb = 6356.755 # 极半径 (km)
Lat_A = airportone['latitude']
Lng_A = airportone['longitude']
Lat_B = airporttwo['latitude']
Lng_B = airporttwo['longitude']
flatten = (ra - rb) / ra # 地球扁率
rad_lat_A = radians(Lat_A)
rad_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
c2 = (sin(xx) + xx) * (sin(pA) - sin(pB)) ** 2 / sin(xx / 2) ** 2
dr = flatten / 8 * (c1 - c2)
distance = ra * (xx + dr)
return distance
airportone = request.form['user_airportone']
airporttwo = request.form['user_airporttwo']
calcDistance(airportone,airporttwo)
Please help, thank you.
淡淡烟草味2017-06-22 11:53:44
def searchcities() -> 'html':
airportone = request.form['user_airportone']
airporttwo = request.form['user_airporttwo']
distanceone = calcDistance['distance']
return render_template('results.html',
the_title = '以下是您选取的机场:',
the_airportone = airportone,
the_airporttwo = airporttwo,
the_distance = distanceone
)
Isn’t this part just to get the airport and then calculate the result and return the distance? The distance is displayed on the
result.html page. Isn’t this all done?