Your SlideShare is downloading. ×
Android Location-based應用開發分享
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Android Location-based應用開發分享

5,472
views

Published on

2008/05/17 TWJUG slides

2008/05/17 TWJUG slides

Published in: Technology, Economy & Finance

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
5,472
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
104
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Location-based 應用開發分享 koji
  • 2. Agenda
    • 一個基本的 Android App
    • 前置工作 - 製造假路徑
    • 寫一個 Location-based 的程式所需的 API
    • 落選作品介紹
  • 3. 一個基本的 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 ));
        • }});
      • }
    • }
  • 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 Map
    • public 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. 落選作品介紹
    • 搭便車系統
    • 實體炸彈超人