Location-based 應用開發分享 koji
Agenda 一個基本的 Android App 前置工作 - 製造假路徑 寫一個 Location-based 的程式所需的 API 落選作品介紹
一個基本的 Android App public   class  BomberMan  extends  Activity { @Override public   void  onCreate(Bundle icicle) { super .onCreate(icicle); setContentView(R.layout. main ); Button joinButton = (Button) findViewById(R.id. join ); joinButton.setOnClickListener( new  View.OnClickListener() { public   void  onClick(View view) { startActivity( new  Intent(BomberMan. this , UserConfig. class )); }}); } }
一個基本的 Android App <? xml  version = &quot;1.0&quot;  encoding = &quot;utf-8&quot; ?> < LinearLayout ... > < RelativeLayout ... > < Button  android:id = &quot;@+id/join&quot; ... /> </ RelativeLayout >   </ LinearLayout >
前置工作 - 製造假路徑 現在的模擬器有個資料夾 /data/misc/location/gps
前置工作 - 製造假路徑 底下可以放四種檔案 ( 越上面越優先 ) Class  Kml  Google Earth nmea  NMEA 0183   Track  <time> <longitude> <latitude> <altitude>
前置工作 - 設定存取權限 < uses-permission android:name = &quot;android.permission. ACCESS_LOCATION&quot;  /> < uses-permission android:name = &quot;android.permission. ACCESS_GPS&quot;  />
所需的 API- 取得座標 LocationManager  locationManager = (LocationManager) getSystemService(Context. LOCATION_SERVICE ); LocationProvider  myProvider =  null ; for  (LocationProvider provider : locationManager.getProviders()) { myProvider = provider; } final   Location  location = locationManager. getCurrentLocation(myProvider.getName());
所需的 API-Google Map public   class  BomberManMap  extends  MapActivity{ ..... this . mapView  =  new  MapView( this ) { @Override public   boolean  onTouchEvent(MotionEvent ev) { return   false ;}}; this .setContentView( mapView ); }
所需的 API- 註冊 listener 寫一個IntenetReceiver class  MyIntentReceiver  extends  IntentReceiver { @Override   public   void  onReceiveIntent(Context context, Intent intent) { Location location = (Location) intent.getExtras().get( &quot;location&quot; ); double  lat = location.getLatitude() * 1E6; double  lon = location.getLongitude() * 1E6; final  Point point =  new  Point(( int ) lat, ( int ) lon); mapView .getController().centerMapTo(point,  true ); mapView .invalidate(); }}
所需的 API- 註冊 listener 註冊 String  MY_LOCATION_CHANGED_ACTION  =  new  String( &quot;android.intent.action.LOCATION_CHANGED&quot; ); IntentFilter  myIntentFilter  =  new  IntentFilter( MY_LOCATION_CHANGED_ACTION ); .....
所需的 API- 註冊 listener 註冊 this . locationManager .requestUpdates( myProvider,  // 剛剛的 provider MINIMUM_TIME_BETWEEN_UPDATE ,  // 最少所需更新的時間 MINIMUM_DISTANCECHANGE_FOR_UPDATE ,  // 所需更新的距離 new  Intent( MY_LOCATION_CHANGED_ACTION )); ... this .registerReceiver( this . myIntentReceiver ,  this . myIntentFilter );
落選作品介紹 搭便車系統 實體炸彈超人

Android Location-based應用開發分享

  • 1.
  • 2.
    Agenda 一個基本的 AndroidApp 前置工作 - 製造假路徑 寫一個 Location-based 的程式所需的 API 落選作品介紹
  • 3.
    一個基本的 Android Apppublic class BomberMan extends Activity { @Override public void onCreate(Bundle icicle) { super .onCreate(icicle); setContentView(R.layout. main ); Button joinButton = (Button) findViewById(R.id. join ); joinButton.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { startActivity( new Intent(BomberMan. this , UserConfig. class )); }}); } }
  • 4.
    一個基本的 Android App<? xml version = &quot;1.0&quot; encoding = &quot;utf-8&quot; ?> < LinearLayout ... > < RelativeLayout ... > < Button android:id = &quot;@+id/join&quot; ... /> </ RelativeLayout > </ LinearLayout >
  • 5.
    前置工作 - 製造假路徑現在的模擬器有個資料夾 /data/misc/location/gps
  • 6.
    前置工作 - 製造假路徑底下可以放四種檔案 ( 越上面越優先 ) Class Kml Google Earth nmea NMEA 0183 Track <time> <longitude> <latitude> <altitude>
  • 7.
    前置工作 - 設定存取權限< uses-permission android:name = &quot;android.permission. ACCESS_LOCATION&quot; /> < uses-permission android:name = &quot;android.permission. ACCESS_GPS&quot; />
  • 8.
    所需的 API- 取得座標LocationManager locationManager = (LocationManager) getSystemService(Context. LOCATION_SERVICE ); LocationProvider myProvider = null ; for (LocationProvider provider : locationManager.getProviders()) { myProvider = provider; } final Location location = locationManager. getCurrentLocation(myProvider.getName());
  • 9.
    所需的 API-Google Mappublic class BomberManMap extends MapActivity{ ..... this . mapView = new MapView( this ) { @Override public boolean onTouchEvent(MotionEvent ev) { return false ;}}; this .setContentView( mapView ); }
  • 10.
    所需的 API- 註冊listener 寫一個IntenetReceiver class MyIntentReceiver extends IntentReceiver { @Override public void onReceiveIntent(Context context, Intent intent) { Location location = (Location) intent.getExtras().get( &quot;location&quot; ); double lat = location.getLatitude() * 1E6; double lon = location.getLongitude() * 1E6; final Point point = new Point(( int ) lat, ( int ) lon); mapView .getController().centerMapTo(point, true ); mapView .invalidate(); }}
  • 11.
    所需的 API- 註冊listener 註冊 String MY_LOCATION_CHANGED_ACTION = new String( &quot;android.intent.action.LOCATION_CHANGED&quot; ); IntentFilter myIntentFilter = new IntentFilter( MY_LOCATION_CHANGED_ACTION ); .....
  • 12.
    所需的 API- 註冊listener 註冊 this . locationManager .requestUpdates( myProvider, // 剛剛的 provider MINIMUM_TIME_BETWEEN_UPDATE , // 最少所需更新的時間 MINIMUM_DISTANCECHANGE_FOR_UPDATE , // 所需更新的距離 new Intent( MY_LOCATION_CHANGED_ACTION )); ... this .registerReceiver( this . myIntentReceiver , this . myIntentFilter );
  • 13.