我正在为一个项目创建一个项目,该项目可以推荐城市中的旅游地点。
如果我有一堆餐厅的位置在我的数据库,我让用户输入他们的位置,什么是最好的方式推荐餐厅关闭他们。我不会仅仅根据位置推荐,但我只是不知道最好的方法去做这件事。我愿意学习,我只是不知道从哪里开始!
让用户输入他们的位置(比如邮政编码)就足够了--我不知道我是否有足够的技术技能来使用gps,我可以使用API等等。
发布于 2022-04-23 21:39:53
这里有几个问题。
PyProj Python库是使用pyproj.Transformer转换协调位置的标准。sklearn Python库能做到这一点。发布于 2022-04-23 22:24:13
使用欧氏距离公式:

哪里

在python中简单地编码为
x**0.5如果您想了解x**0.5vs math.sqrt(x) 阅读这篇文章的性能
以及在哪里

在python中简单地编码为
x**2然后,
您可以使用这个非常基本的具有指导性的python代码:
#location in tuple (x,y)
user_location = (8,9)
#This is dictionary with:
#keys being names of Restaurants
#values being tuples with the position (x,y)
locations={"MacDonald's": (-4,-8),
"TGI Fridays": (1,1),
"Bembos": (2,3),
"Burger King": (5,6),
"El Limeño": (7,8),
"Astrid y Gastón":(-1,10),
"Central": (1,9),
"Johnny Rockets": (6,1)
}
#Extract x,y value from tuple user_location
user_x,user_y = user_location
dist_min=float('inf')
for key in locations:
x,y=locations[key]
#Euclidean's Distance Expression presented earlier
dist=((x-user_x)**2+(y-user_y)**2)**0.5
print(f"Location:({x},{y}) Name:{key} / Distance:{dist:4.3f}" )
if dist<dist_min:
dist_min = dist
best_key = key
print("\n")
print(f"The selected location is {best_key} since it has th smallest distance to the user:{dist_min:4.3f}")复制并粘贴这段代码,它很简单。
我希望它在某种程度上有所帮助。
https://stackoverflow.com/questions/71983589
复制相似问题