ValueError:必须是坐标对或Point

时间:2019-09-03 10:42:26

标签: python-3.x flask geopy

我想将纬度和经度值传递到烧瓶路线,但每次遇到此错误时: ValueError:必须是坐标对或Point

但是我已经尝试过了并且工作正常:

from flask import Flask, render_template 
from geopy.geocoders import Nominatim


app = Flask(__name__)

geolocator = Nominatim()



@app.route('/location')
def lang_and_lat():
    location = geolocator.reverse("21.0943, 81.0337")

    address = location.address

    return render_template('ip.html', address=address)


if __name__ == '__main__':
    app.run(debug=True)
from flask import Flask, render_template 
from geopy.geocoders import Nominatim


app = Flask(__name__)

geolocator = Nominatim()



@app.route('/location/<lat>/<lang>')
def lang_and_lat(lat, lang):
    location = geolocator.reverse(lat, lang)

    address = location.address

    return render_template('ip.html', address=address)


if __name__ == '__main__':
    app.run(debug=True)

1 个答案:

答案 0 :(得分:1)

您需要做 location = geolocator.reverse(f'{lat}, {lang}')

location = geolocator.reverse(Point(lat, lang)) 在第二种情况下,您需要from geopy.point import Point