html5-img
1 / 18

Location-Based services

Location-Based services. Maps. LBS og android. LBS er et add-on Understøttes af LBS- API et: to packages android.location com.google.android.maps. LocationManager. Faciliteter Find positionen Periodiske updates om positionen

dorit
Download Presentation

Location-Based services

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Location-Based services

  2. Maps

  3. LBS og android • LBS er et add-on • Understøttes af LBS-APIet: to packages • android.location • com.google.android.maps

  4. LocationManager • Faciliteter • Find positionen • Periodiske updates ompositionen • “Fire” en application-specifiseretIntentnårtelefonenkommerinærhedenaf en given position • Applikationenkangøretre ting: • Spørgeefter listen afalleLocationProviderssomerkendtafLocationManager for deressidstekendte position. • Register/unregister for periodiskeopdateringeraf position fra en LocationProvider • Register/unregister for at en bestemtIntentbliver “fired” nårtelefonenkommertætpå en given position (specificeretved en radius I meter)

  5. Location • En klasse der repræsenterer en geografisk position på et bestemt tidspunkt (et "fix"). En placering består af en breddegrad og længdegrad og et UTC tidsstempel.

  6. Andre klasser • Address • Geocoder • (længdegrad, breddegrad) <-> adresse • Criteria • Bruges til valg af location provider • Batteri forbruug • GPS, mobilpositionering, akkuratesse, …

  7. Eksempel public voidonCreate(BundleSavedInstanceState) { … LocationManagerlocationManager; Stringcontext = Context.LOCATION_SERVICE; locationManager = (LocationManager)getSystemService(context); Stringprovider = LocationManager.GPS_PROVIDER; Location location = locationManager.getLastKnownLocation(provider); updateWithNewLocation(location); }

  8. updateWithNewLocation private voidupdateWithNewLocation(Location location) { StringlatLongString; … if (location != null) { double lat = location.getLatitude(); double lng = location.getLongitude(); latLongString = "Lat:" + lat + "\nLong:" + lng; } else { latLongString = "No location found"; } myLocationText.setText("Your Current Position is:\n" + latLongString); }

  9. Access • Giv tilgang til lokations-info: • I manifest-filen: <uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/> • Eller • <uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION"/> • Barn af manifest-knuden

  10. Eksempel - opdateringer • Lav en LocationListener (typisk som anonym klasse) private final LocationListenerlocationListener = new LocationListener() { public voidonLocationChanged(Location location) { updateWithNewLocation(location); } public voidonProviderDisabled(Stringprovider){ updateWithNewLocation(null); } public voidonProviderEnabled(Stringprovider){ } public voidonStatusChanged(Stringprovider, int status, Bundleextras){ } };

  11. Anvend Listener • Brug den: locationManager.requestLocationUpdates (provider, 2000, 10, locationListener); Sende besked hvert 2000 msek Hvis telefonen er flyttet mindst 10 meter Beskeden skal sendes til dene

  12. Find lokationsprovider Criteriacriteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //få bedste providerift kriterier Stringprovider = locationManager.getBestProvider(criteria, true)

  13. GoogleMaps • MapView • Activity som kan vise et Map • Ikke en del af std. Android • GoogleAPIs • Vælg det som tar-get platform

  14. Mapaccess • Tilladelse til at bruge net: <uses-permissionandroid:name="android.permission.INTERNET"/> • Brug map-pakke<uses-libraryandroid:name="com.google.android.maps" /> (del af <application>) • Begge dele i manifestfilen

  15. Map på brugergrænsefladen <com.google.android.maps.MapView android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="0Kvw2kImVeCzR7sPmK4LbRepVeJCyuDsw8EXC1Q" /> API key. Hvordan den fås se noter

  16. Eksempel public class HelloMapView extends MapActivity { MapViewmapView; @Override public voidonCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); Double lat = 55.412475*1E6; Double lng = 10.325496*1E6; GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue()); MapControllermapController = mapView.getController(); mapController.setCenter(point); mapController.setZoom(10); } @Override protectedbooleanisRouteDisplayed() {return false;} }

  17. Tegne på kortet • Jeres opgave ;-) • I skal gennemgå tutorialenHelloMapViex.doc (lig http://developer.android.com/guide/tutorials/views/hello-mapview.html)

More Related