私は現在、ショーリストのウェブサイトに取り組んでいます。さまざまな方法でソートされたユーザーの場所ごとに番組情報を表示します。
ユーザーが最初にサイトにサインインしたときに、ユーザーに現在地を尋ねることはできますが、多くのサイトには、場所を自動的に検出するこの機能が組み込まれていることに気付きました(例、Last.fmの「イベント:コンサートリスト」を参照)。範囲")。
彼らはこれをどのように行うのですか?現在、RubyonRailsでWebサイトを構築しています。
私は現在、ショーリストのウェブサイトに取り組んでいます。さまざまな方法でソートされたユーザーの場所ごとに番組情報を表示します。
ユーザーが最初にサイトにサインインしたときに、ユーザーに現在地を尋ねることはできますが、多くのサイトには、場所を自動的に検出するこの機能が組み込まれていることに気付きました(例、Last.fmの「イベント:コンサートリスト」を参照)。範囲")。
彼らはこれをどのように行うのですか?現在、RubyonRailsでWebサイトを構築しています。
関連するGoogleMapsAPIのドキュメントへのリンクは次のとおりです。
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";
}
そして、あなたがそれから何を得るかをあなたに伝えます:
設定されると、
google.loader.ClientLocation
オブジェクトには次のメトロレベルの粒度プロパティが設定されます。
ClientLocation.latitude
—クライアントのIPアドレスに関連付けられた低解像度の緯度を提供します
ClientLocation.longitude
—クライアントのIPアドレスに関連付けられた低解像度の経度を提供します
ClientLocation.address.city
—クライアントのIPアドレスに関連付けられている都市の名前を提供します
ClientLocation.address.country
—クライアントのIPアドレスに関連付けられている国の名前を提供しますClientLocation.address.country_code —クライアントのIPアドレスに関連付けられたISO3166-1国コードの名前を提供します
ClientLocation.address.region —クライアントのIPアドレスに関連付けられた国固有の地域名を提供します
彼らは通常、IPテーブルによるIP解決を使用します。 ip2nationはいくつかのアイデアを与えるかもしれません
MaxMindのGeoLiteソリューションでIPの場所を確認することをお勧めします。オープンソースソリューション。
http://humbuckercode.co.uk/licks/gems/geoip/は、Maxminds の無料または有料のライブラリを使用したシンプルな gem です。
簡単にセットアップでき、スキーマの更新は必要ありません。
There is a new way, in fact it's the better way to find the geographical location, because the browser will natively support the W3C API for geolocation... You should check out GeoMereLaal.