基于位置的信息
我想根据用户的地理位置在我的网站上显示信息。在我当前的设计中,不希望用户输入他们的位置/邮政编码。 使用 IP 我可以找到用户的位置,但我如何利用此信息来显示周围城市/城镇的相关事件/信息。
谢谢
I would like to show information on my website based on user's geography. In my current design would not want the user to enter their location/zip code.
Using IP I can find user's location but how do i leverage this information to show relevant events/information from surrounding cities/town.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基于 IP,您在显示位置方面只能具有一定的准确性。您应该有一个选项可以让他们输入城市/州或邮政编码。
一旦获得经/纬度,您只需运行查询即可在数据库中查找距该经/纬度特定距离的记录。
PHP/MySQL:选择接近给定的位置来自数据库的位置
Based on IPs, you only have a certain accuracy with showing location. You should have a option that lets them enter their city/state or zip code.
Once you have long/lat, you just need to run a query to find records in your database a specific distance from that long/lat.
PHP/MySQL: Select locations close to a given location from DB
http://www.ipinfodb.com/ip_location_api.php
这将向您发送 xml 响应以及相关信息
http://www.ipinfodb.com/ip_location_api.php
this will send you an xml response with the pertinent information
假设您可以从 IP 地址获取他们的城市。您需要一个包含与其他数据库条目相关的 ID 的城市数据库。就像:
然后你可以搜索具有你从IP中获得的城市的city_id的餐馆。
关系数据库有很多不同的方法。这只是一个小例子。
Lets say you can get their City from the IP address. You would need a database of cities with ID's that would pertain to other database entries. Like:
Then you could search for restaurants that have the city_id of the city you got from their IP.
There are so many different approaches to relational databases. This is just one small example.