ついでに、GoogleGearsの位置情報も取得してみた
GoogleGearsにも位置情報を持ってくる機能があるので使ってみた。
(結局FireFox3.5も同じものを呼んでいるようなので結果は同じみたい)
では、
事前準備で、Gearsの定義を読込む
では、本体
(1)!window.google || !window.google.gearsは、Gearsが準備できているかの確認。
(2)google.gears.factory.create('beta.geolocation')で位置読み込みのオブジェクトを作成。
(3)getCurrentPositionで位置を取得して第一パラメータ(GGgetPositionがその関数)にコールバックしてくる。
(4)setCenterでGoogleMapに位置をセット。
try {
if(!window.google || !window.google.gears)
throw null;
geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(
GGgetPosition,
function(positionError) {
alert(positionError.message);
}
);
gme_map.setCenter(new GLatLng(lat, lon), 12);
} catch(e){}
読み込む関数を別にしてみたので
function GGgetPosition(position)
{
lat = position.latitude;
lon = position.longitude;
}