1 / 18

Introducing to Location in Android

Introducing to Location in Android. Location is everything. Kamil Lelonek Kamil.Lelonek@student.pwr.wroc.pl. What we gonna talk about ?. Introduction to GEOgraphy How we „ describe ” the Earth? How we calculate coordinates ? Important issues to avoid problems

eudora
Télécharger la présentation

Introducing to Location in Android

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. Introducing to Location in Android Locationiseverything Kamil Lelonek Kamil.Lelonek@student.pwr.wroc.pl

  2. What we gonna talk about? • Introduction to GEOgraphy • How we „describe” the Earth? • How we calculatecoordinates? • Importantissues to avoidproblems • Findinguserlocation • Prepare to coding • Ways to obtaincurrentposition • Thistime emulator ishelpful • Developing Mapsapplication • GeoCoding • Goodold Google Maps API v1 • New look and feelGoogle Maps API v2 • Summary • Navigation • PRO tips for advancedusers • Q&A

  3. Let’sgo backto school (N) West (W) East (E) º - degrees ’ - minutes ’’ - seconds (S)

  4. How to calculateit? 23º25’24’’ S 23º25’24’’ S → – 23,439167 (double) (int) = 1E6 * (double)→ – 23439167 (int)

  5. Attention Problems Extras • Positive and Negativevalues • Latutudegoesfirst • Altitude • Azimuth • Speed Calcuationproblems

  6. Get prepared • Permissions • ACCESS_MOCK_LOCATION - emulator • ACCESS_COARSE_LOCATION - approximate • ACCESS_FINE_LOCATION - precise • ACCESS_LOCATION_EXTRA_COMMANDS • INSTALL_LOCATION_PROVIDER • LocationManager • LocationProvider • LocationListener

  7. LocationManager LocationManagerlocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providersAll = locationManager.getAllProviders(); List<String> providersEnabled= locationManager.getProviders(true); LocationlastKnownLocation = locationManager.getLastKnownLocation(String provider); doublegetLatitude() double getLongitude() if(hasAltitude()) getAltitude() floatdistanceTo(Location dest) String getProvider() Location

  8. Criterias String getBestProvider(Criteria criteria, booleanenabledOnly) Criteriacriteria = newCriteria();

  9. LocationProviders of 24 LocationProvidergetProvider(String name) booleanhasMonetaryCost() booleanrequiresCell() booleanrequiresNetwork() booleanrequiresSatellite() booleansupportsAltitude() booleansupportsBearing() booleansupportsSpeed()

  10. LocationListener • newLocationListener() { • @Override • public voidonStatusChanged(String provider, int status, Bundle extras) {} • @Override • public voidonProviderEnabled(String provider) {} • @Override • public voidonProviderDisabled(String provider) {} • @Override • public voidonLocationChanged(Locationlocation) {} • } void requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)

  11. Using Emulator and DDMS > telnet localhost 5554 > geo fix -122.08409637.422005

  12. GeoCoding privatevoiddoInBackground() { List<Address> foundGeocode; doublelatitude; doublelongitude; try { foundGeocode = newGeocoder(this).getFromLocationName("ADDRESS", N); for(int n = 0; n < N; n++) { latitude= foundGeocode.get(n).getLatitude(); longitude= foundGeocode.get(n).getLongitude(); } } catch(IOException) { // Log.e(...); } }

  13. Google Maps Android v1 API Note: Version 1 of the Google Maps Android API has been officially deprecated as of December 3rd, 2012. This means that from March 18th, 2013 you will no longer be able to request an API key for this version. No new features will be added to Google Maps Android API v1. However, apps using v1 will continue to work on devices. Existing and new developers are encouraged to use Google Maps Android API v2. (Deprecated?)

  14. private void setUpMap() { mapView = (MapView) findViewById(R.id.mapView); mapView.setBuiltInZoomControls(true); mapView.setOnSingleTapListener(new OnSingleTapListener() { @Override public booleanonSingleTap(MotionEvent e) {} }); mapOverlays = mapView.getOverlays(); myLocationOverlay = new MyLocationOverlay(this, mapView); myLocationOverlay.enableMyLocation(); myLocationOverlay.enableCompass(); myLocationOverlay.runOnFirstFix(new Runnable() { @Override public void run() { MapControllermapController = mapView.getController(); mapController.animateTo(currentLocation); mapController.setZoom(17); mapView.getOverlays().add(myLocationOverlay); } }); mapOverlays.add(myLocationOverlay); Google MapsAndroid v1 API

  15. Google Maps Android API v2

  16. Google Maps Android API v2

  17. // Construct a CameraPosition focusing on PWr // and animate the camera to that position. • CameraPositioncameraPosition = new CameraPosition.Builder()    .target(newLatLng(51.107359,17.059974)) // Sets the center of the map to C-13    .zoom(17)                   // Sets the zoom    .bearing(90)                // Sets the orientation of the camera to east    .tilt(30)                   // Sets the tilt of the camera to 30 degrees    .build();                   // Creates a CameraPosition from the buildermap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); • Weaknesses: • No Android Emulator suport! • Poordocumented… • Requirespowerfulldevice to display 3D view Google Maps Android API v2

  18. Efficency Summary • Networking data • Battery saving It would be quite nice to remember and takecareabout:

More Related