- 2007-12-03 22:53
- android
AndroidではGPSを利用することができます。
AndroidではGPSの概念を拡張したLocation-based ServiceというAPIが準備されています。
では早速使ってみます。
GPS情報を取得する
Activityクラスに準備されているシステムサービスを呼び出します。
locman = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
これでLocationManagerを取得できました。
次にLocationManagerのGPSを取得します。
Location loc = locman.getCurrentLocation("gps");
これで場所情報を取得できました。これで緯度と経度が取得できます。
double latitude = loc.getLatitude();//緯度 double longitude = loc.getLongitude();//経度
シミュレータでは緯度と経度はそれぞれ37.42237166666666と-122.09652833333332です。Googleの本社の近くのようです。
おわりに
意外というか流石というか、簡単にGPSデータが取得できました。
シミュレータなので位置情報を変えられないのが残念。
もしかしてちゃんと変更できたりするのかなぁ?
関連のありそうなエントリ
- Newer: AndroidでSDカードを利用する方法
- Older: Androidで地図を表示する方法
Comments:0
Trackbacks:0
- Trackback URL for this entry
- http://www.adamrocker.com/blog/169/how_to_get_gps_location_with_android.html/trackback/
- Listed below are links to weblogs that reference
- AndroidでGPSを使って現在地を取得する方法 from throw Life
