• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Android App Development 04 : Location API
 

Android App Development 04 : Location API

on

  • 648 views

 

Statistics

Views

Total Views
648
Views on SlideShare
641
Embed Views
7

Actions

Likes
1
Downloads
27
Comments
0

1 Embed 7

http://www.classstart.org 7

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Android App Development 04 : Location API Android App Development 04 : Location API Presentation Transcript

    • 4 Location API Anuchit Chalothorn anoochit@gmail.comLicensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
    • Determine the current locationMost Android devices allow to determine thecurrent geolocation. This can be done via aGPS (Global Positioning System) module, viacell tower triangulation or via wifi networks.Ref: http://developer.android.com/guide/topics/location/index.html
    • Location ManagerThe LocationManager class provides access tothe Android location service. This servicesallows to access location providers, to registerlocation update listeners and proximity alertsand more.
    • LocationProviderThe LocationProvider class is the superclass ofthe different location providers which deliver theinformation about the current location. Thisinformation is stored in the Location class.
    • LocationProviderLocationProvider Descriptionnetwork Uses the mobile network or WI-Fi to determine the best location. Might have a higher precision in closed rooms then GPS.gps Use the GPS receiver in the Android device to determine the best location via satellites. Usually better precision than network.passive Allows to participate in location of updates of other components to save energy
    • Selecting LocationProvider via CriteriaFor a flexible selection of the best locationprovider use a Criteria object, in which you candefine how the provider should be selected.
    • PermissionIf you want to access the GPS sensor, youneed the ACCESS_FINE_LOCATIONpermission. Otherwise you need theACCESS_COARSE_LOCATION permission.
    • Prompt the user to Enabled GPSLocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);boolean enabled = service .isProviderEnabled(LocationManager.GPS_PROVIDER);if (!enabled) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent);}
    • Workshop: Get current locationUse criteria find the best provider then getcurrent position from it.LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);Criteria criteria = new Criteria();String provider = locationManager.getBestProvider(criteria, true);Location location = locationManager.getLastKnownLocation(provider);float lat = (float) location.getLatitude(); float lon = (float) location.getLongitude();
    • Install Google Play services
    • Google MapsGoogle provides via Google play a library forusing Google Maps in your application. Thefollowing description is based on the GoogleMaps Android API v2 which provides significantimprovements to the older API version.Ref: https://developers.google.com/maps/documentation/android/
    • Getting the Google Map keyTo use Google Maps you need to create a validGoogle Maps API key. The key is free, you canuse it with any of your applications that call theMaps API, and it supports an unlimited numberof users.
    • SHA-1 for your signature keykeytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android
    • Work with Google Map● Register your app and sha1 for publish keystore and debug keystore● Import Google Play Service library● Add some permission and information● Add MapView to layout● then coding
    • MapViewThe library provides the com.google.android.gms.maps.MapFragment class and theMapView class for displaying the mapcomponent.<fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.MapFragment" />
    • Permission
    • API Key
    • Map & Markerstatic final LatLng SIPA = new LatLng(13.885245,100.565586);GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();if (map!=null) { Marker sipa = map.addMarker(new MarkerOptions().position(SIPA).title("SIPA"));}
    • End