新しいAPIをご覧ください。 実際、これはAPIではなく、google.loader.ClientLocationのプロパティにすぎません
Google AJAX APIの一部をロードした後、システムはIPアドレスによってクライアントの地理的位置を見つけようとします。
カードとクライアントのIPアドレスが一致している場合、google.loader.ClientLocationはユーザーの国、地域、都市のおおよその座標を返します。 マッピングは理想とはほど遠いですが、「スマート」なデフォルト設定を使用したり、プロジェクト内の訪問者の位置に関する認識を示すことができます。
google.loader.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 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" ;
}
* This source code was highlighted with Source Code Highlighter .
コードが機能することを確認するには、 2008アメリカ合衆国選挙ページにアクセスしてください 。 「州別ニュース」セクションに移動すると、現在地の州の候補者に関するニュースが表示されるか、地図上の座標とIPアドレスの対応がない場合は、カリフォルニア州の候補者のニュースが表示されます。
快適になりました。 IPアドレスを訪問者の場所にマッピングするメカニズムが気に入った場合は、Gearsチームが準備してくれるものを待つ必要があります 。 彼らは、この機能の最終バージョンを準備しています。これにより、IPアドレス、GPS、および間もなくWiFiによって座標を決定できます。 これは間違いなく機能と精度の両方を改善する方向への飛躍です。