搜索引擎按距离 [英] Search engine by distance
问题描述
我希望在我的网站上选择我的Serach引擎,以便用户可以搜索设置距离内的物品,例如在10英里或20英里等范围内搜索商品.我想知道如何做到这一点?
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?
用户将必须输入他们的邮政编码,而我也要输入该项目的位置的邮政编码,一旦他们点击搜索,就需要离开以工作两个位置之间的距离(以英里为单位),然后按顺序显示结果按距离因为最接近的项目是第一个结果.在使用地图的获取路线"选项来计算以英里为单位的距离时,是否有Google API?还是我可以添加到数据库中的内容?
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?
推荐答案
Google地理编码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
注意:您只能将Geocoding API与Google地图结合使用;禁止对结果进行地理编码而不在地图上显示结果.有关允许使用的完整详细信息,请查阅链接.
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.
因此,例如,如果您请求查找邮政编码94043的邮政编码,则会调用以下URL:
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
使用JSON的结果如下:
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"
}
如果您由于某种原因无法使用Google API,则以下是非Google Geocoder API和服务的列表:
If you cannot use the Google API for some reason then here is list of non-Google Geocoder APIs and services:
- http://code.google.com/p/gmaps- api-issues/wiki/NonGoogleGeocoders
- http://webgis.usc.edu/Services/Geocode/About/GeocoderList.aspx
- http://code.google.com/p/gmaps-api-issues/wiki/NonGoogleGeocoders
- http://webgis.usc.edu/Services/Geocode/About/GeocoderList.aspx
这篇关于搜索引擎按距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!