2011年4月22日金曜日

プログラム開始

教科書をなぞるのも飽きてきたので(オイ…)、自分の好きなプログラムをちょっとずつやってみることにしました。

Android端末でロケーションが取得できる状態で、ボタンをポチっと押すと、取得した現在地情報をもとにして、google maps上にマーカーを置き、画面上部に緯度、経度、高度が出るところまで作りたいな、と思ってやり始めましたが、いろいろ気を取られて今日は全然はかどりませんでした。

まずはmanifestファイルにインターネットアクセス、GPSを使った位置情報取得の許可を記述します。
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>

あと、同じくmanifestファイル内のapplication要素内に、google mapsのライブラリを追加します。
<uses-library android:name="com.google.android.maps" />

manifestファイルの設定はこれで終わりです。

次に、res/layoutのmain.xml内に、UIを記述します。
<TextView
   android:id="@+id/TextView01"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:textColor="@android:color/black"
   android:background="@android:color/white"
   android:textSize="12pt"
/>
<Button
   android:text="位置取得"
   android:id="@+id/Button01"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
/>
<com.google.android.maps.MapView
   android:id="@+id/MapView01"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:apiKey="apiKey"
/>



で、実際に動かしてみたスクリーンショットがこれです。


位置取得ボタンがダサいですが、まあ、テストプログラムだから拘りません。
本当は、googlemaps内に配置したいところですけど。

今日はここまで。

肝心のプログラムは?てな感じですが、まだまだ初心者ゆえ歩みが遅いのです。
許されうむ。

0 件のコメント:

コメントを投稿