full code is HERE
HTML code
<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;
app.py
Latitude = request.form['Latitude']
Longitude = request.form['Longitude']
messages = database.returnMessagesinRange(float(Latitude),float(Longitude))
database.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
When this is run, i get
if ((current['longitude']-longitude) * (current['longitude']-longitude) + (current['latitude']-latitude)*(current['latitude']-latitude)) <= 1:
TypeError: unsupported operand type(s) for -: 'unicode' and 'unicode'
Anyone know why this is happening? thanks.
Both the longitude and latitude retrieved from the request and the database are strings (unicode strings) and you are trying to operate on them as if they were numbers.
You should first get the
intorfloatrepresentation of such strings to be able to operate on them as numbers (using-,*, etc)You can do that by creating a
intorfloatobject passing the string as a parameteror