按距离搜索引擎

发布于 2024-12-16 18:52:59 字数 230 浏览 2 评论 0原文

我希望在我的网站上选择我的搜索引擎,以便用户可以搜索设定距离内的项目,例如搜索 10 英里或 20 英里内的项目等。我想知道如何做到这一点?

用户必须输入他们的邮政编码,而我也有该项目位置的邮政编码,一旦他们点击搜索,就需要离开以英里为单位计算两个位置之间的距离,然后按距离顺序显示结果;因为最接近的项目是第一个结果。是否有谷歌 API 可以使用地图“获取方向”选项来计算距离(以英里为单位)?或者我可以添加到我的数据库中的东西?

I am looking to make an option of my serach engine on my site so that users can search for items within a set distance, e.g. search items within 10 miles, or 20 miles etc. I was wondering how this could be done?

The user would have to enter thier postcode, while i also have the postcode of the item's location and once they hit search there needs to be a away to work the distance between the two locations in miles and then display the results in order by distance; as in the closest item is the first result. Is there a google api for this as in use the maps 'get directions' option to work out the distance in miles? Or something i can add to my database?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她比我温柔 2024-12-23 18:52:59

Google Geocoding API 提供邮政编码查找,并且可以提供国家/地区、城市、纬度/经度(甚至仅提供邮政编码作为地址)。一旦获得了纬度/经度,您就可以轻松计算距离并对结果进行排序。

http://code.google.com/apis/maps/documentation/geocoding/ #GeocodingRequests

注意:您只能将 Geocoding API 与 Google 地图结合使用;禁止对结果进行地理编码而不将其显示在地图上。有关允许使用的完整详细信息,请参阅链接。

例如,如果您请求查找邮政编码 94043,则调用以下 URL:

http://maps.googleapis.com/maps/api/geocode/json?address=94043&sensor=false

这将产生 JSON,如下所示:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "94043",
               "short_name" : "94043",
               "types" : [ "postal_code" ]
            },
           ...
          "location" : {
               "lat" : 37.4284340,
               "lng" : -122.07238160
          },
          "location_type" : "APPROXIMATE",
         ...
   "status" : "OK"
 }

如果您由于某种原因无法使用 Google API,那么这里是非 Google Geocoder API 和服务的列表:

The Google Geocoding API provides zip code lookup and can provide the country, city, lat/lon given even just a zip code as the address. Once you have the lat/lon then you can easily calculate the distance and sort the results.

http://code.google.com/apis/maps/documentation/geocoding/#GeocodingRequests

Note: you can only use the Geocoding API in conjunction with a Google map; geocoding results without displaying them on a map is prohibited. For complete details on allowed usage, consult the link.

So if for example if you request lookup for zip code 94043 you call following URL:

http://maps.googleapis.com/maps/api/geocode/json?address=94043&sensor=false

Which would result with JSON such as following:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "94043",
               "short_name" : "94043",
               "types" : [ "postal_code" ]
            },
           ...
          "location" : {
               "lat" : 37.4284340,
               "lng" : -122.07238160
          },
          "location_type" : "APPROXIMATE",
         ...
   "status" : "OK"
 }

If you cannot use the Google API for some reason then here is list of non-Google Geocoder APIs and services:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文