我目前正在展示列表网站上工作。我将按位置显示用户以各种不同方式排序的显示信息。如何自动查找用户的位置?
我知道我可以问当他们第一次登录到该网站,他们所在的用户,但我注意到,很多网站都这个功能内置自动检测位置(例如,见Last.fm“活动:您所在地区的音乐会清单“)。
他们如何做到这一点?我目前正在使用Ruby on Rails构建我的网站。
我目前正在展示列表网站上工作。我将按位置显示用户以各种不同方式排序的显示信息。如何自动查找用户的位置?
我知道我可以问当他们第一次登录到该网站,他们所在的用户,但我注意到,很多网站都这个功能内置自动检测位置(例如,见Last.fm“活动:您所在地区的音乐会清单“)。
他们如何做到这一点?我目前正在使用Ruby on Rails构建我的网站。
他们通常使用IP桌面使用IP解析。 ip2nation可能会给一些想法
下面是对文件的链接在相关谷歌地图API:
http://code.google.com/apis/ajax/documentation/#ClientLocation
它显示了如何使用它的一个例子:
/**
* Set the currentState_ and currentCountry_ properties based on the client's
* current location (when available and in the US), or to the defaults.
*/
InTheNews.prototype.setDefaultLocation_ = function() {
this.currentState_ = this.options_.startingState;
if (google.loader.ClientLocation &&
google.loader.ClientLocation.address.country_code == "US" &&
google.loader.ClientLocation.address.region) {
// geo locate was successful and user is in the United States. range
// check the region so that we can safely use it when selecting a
// state level polygon overlay
var state = google.loader.ClientLocation.address.region.toUpperCase();
if (InTheNews.stateNames[state]) {
this.currentState_ = state;
}
}
this.currentCountry_ = "US";
}
而且告诉你你会从中得到什么:
012相关联的国家特定区域名称填充后,
google.loader.ClientLocation
对象是 填入下列 地铁级粒度特性:
ClientLocation.latitude
- 提供与客户端的IP地址
ClientLocation.longitude
相关的低分辨率纬度 - 供应与客户端的IP地址相关的低分辨率经度
ClientLocation.address.city
- 提供名称th与客户端的IP地址
ClientLocation.address.country
相关的E都市 - 提供与客户端的IP地址ClientLocation.address.country_code关联的国家的名字 - 供应ISO 3166-1国家代码相关联的名称与客户端的IP地址
ClientLocation.address.region - 提供与客户端的IP地址
您可能会喜欢查看MaxMind's GeoLite解决方案的IP位置。开源解决方案。
有一种新的方式,实际上它是找到地理位置的更好方法,因为浏览器本地支持W3C API进行地理定位......您应该查看GeoMereLaal。
http://humbuckercode.co.uk/licks/gems/geoip/是一个使用Maxminds免费或付费图书馆的简单宝石。
简单的设置,无需更新模式。
不要忘记上传你喜欢的一些答案,并可能标记一个被接受的答案。人们总是可以使用鼓励。 – GEOCHET 2009-02-27 22:58:40
我upvoted三个答案。但有人一直投下一切。 – CodingWithoutComments 2009-02-27 22:59:41
@编码:有趣。继续,很好的问题。 – GEOCHET 2009-02-27 23:01:50