今まで使ってなかった Google Map を使って見ようと思って調べてみた。

とりあえず GPS から現在位置を取ってきて地図を表示させてみることに。

スマホは HTML5 とか標準装備なので 数十行のWebページだけで出来てしまった。

Map API ちょっと面白いかもしれない。

サンプルはここ。

  • http://wsjs-gae.appspot.com/test/gps.html
iPhone、Android、PCでも動く(IE除く)。
PCはIPアドレスから計算しているのか地域レベルまで。
GPS無しの Android でも結構正確に取れる。WiMAX から情報を得ているのかもしれない。

ソース:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no"> <script type="text/javascript"> window.onload = function(){ navigator.geolocation.watchPosition(update); } function update(position){ var lat = position.coords.latitude; var lng = position.coords.longitude; var img = document.getElementById("map"); var url = "http://maps.google.com/maps/api/staticmap" +"?center="+lat+","+lng +"&zoom=15" +"&size=400x400" +"&sensor=false" +"&markers=color:red|"+lat+","+lng ; img.src = url; } </script> </head> <body> <img id="map" src="" /> </body> </html>