Android API Android Manifest xml activity useslibrary android
2.緯度・経度の指定 (エミュレータでも可能) Android APIキーを取得しておくこと。 【Android. Manifest. xml】 ・・・ </activity> <uses-library android: name="com. google. android. maps" /> </application> <uses-permission android: name="android. permission. INTERNET" /> </manifest>
B.関連クラス 概 要 com. google. android. maps. Geo. Pointクラス Geo. Point(int lt, int lg) com. google. android. maps. Map. Viewクラス 緯度・経度から地点を作成 Map. Controller get. Controller() com. google. android. maps. Map. Controllerクラス マップコントローラ取得 void animate. To(Get. Point gp) 指定地点にアニメーションして動かす
C. プログラム例(その1) package jp. map; import com. google. android. maps. *; import android. os. *; import android. view. View. *; import android. widget. *; public class Setgp. Activity extends Map. Activity { Map. View map. V; Edit. Text[] edit. T=new Edit. Text[6]; Text. View[] text. V=new Text. View[6]; Button button; /** Called when the activity is first created. */ @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); Table. Layout TL=new Table. Layout(this); set. Content. View(TL); for(int i=0; i<edit. T. length; i++){ edit. T[i]=new Edit. Text(this); text. V[i]=new Text. View(this); }
プログラム例(その2) text. V[0]. set. Text("度"); text. V[1]. set. Text("分"); text. V[2]. set. Text("秒"); text. V[3]. set. Text("度"); text. V[4]. set. Text("分"); text. V[5]. set. Text("秒"); Table. Row row 1=new Table. Row(this); Table. Row row 2=new Table. Row(this); row 1. add. View(edit. T[0]); row 1. add. View(text. V[0]); row 1. add. View(edit. T[1]); row 1. add. View(text. V[1]); row 1. add. View(edit. T[2]); row 1. add. View(text. V[2]); row 2. add. View(edit. T[3]); row 2. add. View(text. V[3]); row 2. add. View(edit. T[4]); row 2. add. View(text. V[4]); row 2. add. View(edit. T[5]); row 2. add. View(text. V[5]); button=new Button(this); button. set. Text("検索"); map. V=new Map. View(this, "XXXXXXX"); map. V. set. Enabled(true); map. V. set. Clickable(true); map. V. set. Built. In. Zoom. Controls(true);
プログラム例(その3) map. C. set. Zoom(3); TL. add. View(row 1); TL. add. View(row 2); TL. add. View(button); TL. add. View(map. V); button. set. On. Click. Listener(new gp. Click. Listener()); } protected boolean is. Route. Displayed() { return false; } class gp. Click. Listener implements On. Click. Listener{ public void on. Click(View v){ try{ double[] d =new double[6]; for(int i=0; i<edit. T. length; i++){ String str=edit. T[i]. get. Text(). to. String(); d[i]=Double. parse. Double(str); }
プログラム例(その4) int latitude = // 緯度計算 (int)((d[0]+d[1]/60+d[2]/3600)*1000000); int longitude = // 経度計算 (int)((d[3]+d[4]/60+d[5]/3600)*1000000); Geo. Point gp=new Geo. Point(latitude, longitude); map. V. get. Controller(). animate. To(gp); }catch(Number. Format. Exception e){ Toast. make. Text(get. Base. Context(), "数値を入力して下さい", Toast. LENGTH_LONG). show(); } }
- Slides: 7