android location-based應用開發分享
DESCRIPTION
2008/05/17 TWJUG slidesTRANSCRIPT
- 1. Location-based koji
2. Agenda
- Android App
- -
- Location-based API
3. Android App
- public classBomberManextendsActivity {
-
- @Override
-
- public voidonCreate(Bundle icicle) {
-
-
- super .onCreate(icicle);
-
-
-
- setContentView(R.layout. main );
-
-
-
- Button joinButton = (Button) findViewById(R.id. join );
-
-
-
- joinButton.setOnClickListener( newView.OnClickListener() {
-
-
-
- public voidonClick(View view) {
-
-
-
-
- startActivity( newIntent(BomberMan. this , UserConfig. class ));
-
-
-
-
- }});
-
-
- }
- }
4. Android App
- < LinearLayout ... >
-
- < RelativeLayout ... >
-
-
- < Buttonandroid:id = "@+id/join" ... />
-
-
- RelativeLayout >
- LinearLayout >
5. -
-
- /data/misc/location/gps
6. -
- ( )
-
- Class
-
- Kml
-
-
- Google Earth
-
-
- nmea
-
-
- NMEA 0183
-
-
- Track
7. -
- < uses-permission
- android:name = "android.permission.
-
- ACCESS_LOCATION"/>
- < uses-permission
- android:name = "android.permission.
-
- ACCESS_GPS"/>
8. API-
- LocationManagerlocationManager = (LocationManager) getSystemService(Context. LOCATION_SERVICE );
- LocationProvidermyProvider =null ;
- for(LocationProvider provider : locationManager.getProviders()) {
-
- myProvider = provider;
- }
- final Locationlocation = locationManager.
-
- getCurrentLocation(myProvider.getName());
9. API-Google Map
- public classBomberManMapextendsMapActivity{
- .....
-
- this . mapView=newMapView( this ) {
-
- @Override
-
- public booleanonTouchEvent(MotionEvent ev) {
-
-
- return false ;}};
-
-
- this .setContentView( mapView );
- }
10. API- listener
- IntenetReceiver
- classMyIntentReceiverextendsIntentReceiver {
-
- @Override public voidonReceiveIntent(Context context, Intent intent) {
-
-
- Location location = (Location) intent.getExtras().get( "location" );
-
-
-
- doublelat = location.getLatitude() * 1E6;
-
-
-
- doublelon = location.getLongitude() * 1E6;
-
-
-
- finalPoint point =newPoint(( int ) lat, ( int ) lon);
-
-
-
- mapView .getController().centerMapTo(point,true );
-
-
-
- mapView .invalidate();
-
-
- }}
11. API- listener
- StringMY_LOCATION_CHANGED_ACTION=newString( "android.intent.action.LOCATION_CHANGED" );
- IntentFiltermyIntentFilter=newIntentFilter( MY_LOCATION_CHANGED_ACTION );
- .....
12. API- listener
- this . locationManager .requestUpdates(
-
- myProvider,// provider
-
- MINIMUM_TIME_BETWEEN_UPDATE ,//
-
- MINIMUM_DISTANCECHANGE_FOR_UPDATE ,//
-
- newIntent( MY_LOCATION_CHANGED_ACTION ));
-
- ...
- this .registerReceiver( this . myIntentReceiver ,this . myIntentFilter );
13.