忍者ブログ
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。



2024/03/29 03:06 |
Android2.2 名刺管理アプリケーションを作ってみる3日目その4

前回の続き。

http://codezine.jp/article/detail/4657?p=2

マップ画面のデザインを行いましょう。

Androidエミュレータをインストールすると、Documents and Settings以下にいつのまにかGoogleMapAPI用の証明書が保存されているようです。
C:\Documents and Settings\ユーザ名\.android\debug.keystoreがあるかどうか探してみましょう。
見つかったら、その証明書からフィンガープリントを抽出します。

keytoolはJavaに付属してるみたい。
手元ではC:\pleades\jre1.6\binに見つかりました。
keytool -list -keystore "C:\Documents and Settings\ユーザ名\.android\debug.keystore"
を実行します。

パスワードは何も入れずにリターン。
:で区切られたMD5が取得できます。
このパスワードはどういう意味かよくわかんない。

次にここからMD5を入力すると、APIキーとMapViewのコードを取得できます。
http://code.google.com/intl/ja/android/add-ons/google-apis/maps-api-signup.html


以後はMapViewのコードをビューにそのまま書くだけで簡単にGoogleMapAPIを利用できるようになります。

/res/layout/map.xml 

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent" android:layout_height="fill_parent">

	<!-- 地図 -->
	<com.google.android.maps.MapView
		android:id="@+id/map"
		android:layout_width="fill_parent"
		android:layout_height="fill_parent"
		android:apiKey="0PvsHuDZcbz3WPMOPTMG2N02xrRdJDF5pX2YsWQ" />

	<!-- 地図の上に半透明のレイアウトを配置 -->
	<LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#99000080"
        android:padding="2px" >

	    <!-- 地図切り替えのラジオボタン -->
        <RadioGroup
	        android:id="@+id/mapRadioGroup"
	        android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <!-- 通常の地図ボタン -->
            <RadioButton
                android:id="@+id/normalMapRadio"
                android:text="@string/map"
                android:textColor="#FFFFFFFF"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <!-- 衛星写真ボタン -->
            <RadioButton
                android:id="@+id/satelliteMapRadio"
                android:text="@string/map_satellite"
                android:textColor="#FFFFFFFF"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </RadioGroup>

	   	<!-- 現在地表示のトグルボタン -->
        <ToggleButton
            android:id="@+id/currentLocationToggle"
            android:layout_gravity="right|center_vertical"
            android:textOff="@string/current_location_off"
            android:textOn="@string/current_location_on"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
	</LinearLayout>
</FrameLayout>


<FrameLayout>は、部品を並べると単純に画面左上詰めで追加するという最もシンプルなレイアウトです。
今回の場合、まずMapViewで全画面にマップを表示し、その後LinearLayoutを重ねるということになります。
LinearLayoutはandroid:orientation="horizontal"が指定されているので、中にあるふたつの部品、RadioGroupとToggleButtonが左右に並んで表示されます。

背景色はandroid:background="#99000080"となっていますが、指定方法は"#aarrggbb""#rrggbb"です。aaは透明度。

/src/com.example.bizcard/ListActivity.java
public class MapActivity extends com.google.android.maps.MapActivity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.map);
	}
	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}
}


これまでアクティビティはすべてandroid.app.Activityクラスを継承していましたが、GoogleMapAPIを利用するアクティビティはcom.google.android.maps.MapActivityを継承する必要があります。
onCreateは全く同じですが、isRouteDisplayedという謎メソッドが追加されています。
ルート表示を行うならtrueだそうですが何のことやら、とりあえずfalseにしておきます。

最後にマニフェストを追加。
/AndroidManifest.xml
<activity android:name=".MapActivity"
		  android:label="@string/app_name">
	<intent-filter>
		<action android:name="android.intent.action.MAIN" />
	</intent-filter>
</activity>

ここまでは同じですが、GoogleMapに接続するためにインターネット接続権限を付与しないといけません。
<application>の外側、<manifest>の直下に設置します。
    <uses-permission android:name="android.permission.INTERNET" />

また、GoogleMapAPIを使用しているのでそれを宣言して取り込まないといけないようです。
こちらは<application>直下に記述します。
    <uses-library android:name="com.google.android.maps" />

何故書くレベルが違うんだ?
どっちもアプリ単位とかアクティビティ単位じゃ駄目なのか?

実行。
無事にマップの取得に成功。
 

ボタンやドラッグなどの機能は何も実装していないので、現状では見るだけです。


Androidの記事

 


PR


2010/07/19 20:22 | Comments(0) | TrackBack() | Android

トラックバック

トラックバックURL:

コメント

コメントを投稿する






Vodafone絵文字 i-mode絵文字 Ezweb絵文字 (絵文字)



<<Kinectは150ドル | HOME | 買ったものリスト 2010/07/18>>
忍者ブログ[PR]