Fork me on GitHub

2008/08/22

Recent entries from same category

  1. javascriptで動くtwitter streamクライアントを作るならばmultipart/mixedを使うべき Hatena
  2. バッチファイルで簡易Webサーバを起動する。 Hatena
  3. twitter.bat Hatena
  4. XSLTを使ったAmazon最速検索が動くようになった。 Hatena
  5. IEとFirefox/Google Chromeでクリック/ダブルクリックの発生回数が異なる。 Hatena

はてな
APIs for Finding Location

Google launched two APIs for finding the location of a user from a web application. The most simple way, which is also the least precise, is to derive some information about location from the IP. Google AJAX API has an object named google.loader.ClientLocation that includes "metro-level granularity properties": country, region, city, low resolution latitude and longitude. This could be useful if you want to customize a web page for a specific country or to prefill information about location. You probably noticed that google.com automatically redirects to the appropriate international domain and that when you create a Google account your country is already selected.

http://googlesystem.blogspot.com/2008/08/apis-for-finding-location.html

Developer's Guide - Google AJAX APIs - Google Code

When an application makes used of the AJAX API loader, the loader attempts to geo locate the client based on it's IP address. If this process succeeds, the client's location, scoped to the metro level, is made available in the google.loader.ClientLocation property. If the process fails to find a match, this property is set to null.

http://code.google.com/apis/ajax/documentation/#ClientLocation http://code.google.com/apis/gears/api_geolocation.html
試しにやってみたら"google.loader.ClientLocation.address.region"で"「大阪府」って出た。
あと"ClientLocation.latitude"と"ClientLocation.longitude"で緯度経度が得られるので、setCenterで中心位置を変更出来る。
google.load("maps", "2");
google.load("search", "1");
google.setOnLoadCallback(function() {
    var map = new google.maps.Map2(document.getElementById("map"));
    map.setCenter(new google.maps.LatLng(
        google.loader.ClientLocation.latitude,
        google.loader.ClientLocation.longitude), 10);
});
実行結果は以下
どんどん便利になってく。

blog comments powered by Disqus
WriteBacks

TrackBack ping me at
Post a comment

writeback message: Ready to post a comment.