如何制作“ xx公里”来自位置、地理/谷歌 API
好的,我有一份餐厅名单。所有餐厅都有一个地址,我想这样做,您可以在输入字段中写一个位置,然后它将显示距离最近的餐厅列表,然后按降序排列。示例:
搜索:Valby(位于的城市)丹麦)
Restaurant Ankrara - 2 km from Valby
Restaurant JuicyFood - 3 km from Valby
Restaurant FoodJuicy - 5 km from Valby
Restaurant Blabla - 22 km from Valby
经过对 SO 的研究和提问,我发现我需要使用地理编码和谷歌地图 api。
好的,现在我已经将您输入的内容(上例中的城市瓦尔比)转换为地理编码(纬度/经度坐标)。
然后我就有了坐标中的地址。
如何计算城市与餐厅地址之间的公里数坐标?
例如,这里是城市“Valby”的绳索:
55.662133, 12.508028
这是 3 家餐厅的地址绳索:(
55.667029, 12.527715
55.6939821, 12.4934945
55.6696885, 12.3755492
我如何以最近/最近的方式显示它们,然后降序 <- 不需要接受的答案,我最终做出这是一个新问题)
Ok I have a restaurant list. All the restaurants have a adresses, and I would like to do so you can write a location in a input field, and then it will show the restaurant list with the closest first and then descending.. example:
Searching for: Valby (city in Denmark)
Restaurant Ankrara - 2 km from Valby
Restaurant JuicyFood - 3 km from Valby
Restaurant FoodJuicy - 5 km from Valby
Restaurant Blabla - 22 km from Valby
After research and question here on SO, I found out I need to use geocoding and google maps api.
Okay, so I got to the step where I have converted what you entered (the city Valby in above example), into geocode (lat/lng coordinates).
And then i have the adresses in the coordinates to.
How can i count the kilometers between the City and the restaurant address in coordinates?
For the example, here is the cords of the city "Valby":
55.662133, 12.508028
And here is 3 restaurants addresses cords:
55.667029, 12.527715
55.6939821, 12.4934945
55.6696885, 12.3755492
(And how can i show them with closest/nearest first and then descending <- not required for accepted answer, I eventually make a new question for this)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以计算距离:
然后对它们进行排序:
有关详细信息,请参阅在 jsfiddle 上运行源代码。
You can compute the distances:
and then sort them:
For details see the running source code on jsfiddle.
您可以在服务器上计算距离。请参阅文章使用 PHP、MySQL 和 PHP 创建商店定位器谷歌地图
You can compute the distances on your server. See article Creating a Store Locator with PHP, MySQL & Google Maps