完整代码在这里
HTML 代码
<input type="hidden" id="Latitude" name="Latitude" value={{Longitude}} />
<input type="hidden" id="Longitude" name="Longitude" value={{Longitude}} />
document.getElementById("Latitude").value = position.coords.latitude;
document.getElementById("Longitude").value = position.coords.longitude;
应用程序.py
Latitude = request.form['Latitude']
Longitude = request.form['Longitude']
messages = database.returnMessagesinRange(float(Latitude),float(Longitude))
数据库.py
def returnMessagesinRange(longitude,latitude):
allMessages = Messages.find()
messagesinRange = []
for current in allMessages:
if ((current['longitude']-longitude) * (current['longitude']-longitude) + (current['latitude']-latitude)*(current['latitude']-latitude)) <= 1:
if messagesinRange == None:
messagesinRange = [current['text']]
else:
messagesinRange.append(current['text'])
return messagesinRange
当它运行时,我得到
if ((current['longitude']-longitude) * (current['longitude']-longitude) + (current['latitude']-latitude)*(current['latitude']-latitude)) <= 1:
TypeError: unsupported operand type(s) for -: 'unicode' and 'unicode'
有谁知道为什么会这样?谢谢。