Lecture 5: Location Topics: Google Play Services, Location API Date: Feb 16, 2016.

Slides:



Advertisements
Similar presentations
Android Application Development Tutorial. Topics Lecture 4 Overview Overview of Sensors Programming Tutorial 1: Tracking location with GPS and Google.
Advertisements

Threads, Surface Views and Real-Time Games. Background Most of the Android apps we’ve covered so far have been single threaded – And Event driven – An.
CSE2102 Introduction to Software Engineering Lab 2 Sept/4/2013.
Programming with Android: Activities
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
CS378 - Mobile Computing Maps. Using Google Maps Like other web services requires an API key from Google ons/google-apis/mapkey.html.
The Activity Class 1.  One application component type  Provides a visual interface for a single screen  Typically supports one thing a user can do,
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Location Services: Part 1 (Location and Geocoding)
Software Architecture of Android Yaodong Bi, Ph.D. Department of Computing Sciences University of Scranton.
Location based services Using Google Maps v2 etc. in Android apps 1Location based services.
Mobile Programming Lecture 9 Bound Service, Location, Sensors, IntentFilter.
Mobile Programming Lecture 16 The Facebook API. Agenda The Setup Hello, Facebook User Facebook Permissions Access Token Logging Out Graph API.
CSS216 MOBILE PROGRAMMING Android, Chapter 8 Book: “Professional Android™ 2 Application Development” by Reto Meier, 2010 by: Andrey Bogdanchikov (
Cosc 5/4730 Introduction: Threads, Android Activities, and MVC.
Cosc 5/4730 Broadcast Receiver. Broadcast receiver A broadcast receiver (short receiver) – is an Android component which allows you to register for system.
DUE Hello World on the Android Platform.
CS378 - Mobile Computing Intents.
Android Accessing GPS Ken Nguyen Clayton State University 2012.
1 CMSC 628: Introduction to Mobile Computing Nilanjan Banerjee Introduction to Mobile Computing University of Maryland Baltimore County
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
Threads and Services. Background Processes One of the key differences between Android and iPhone is the ability to run things in the background on Android.
Cosc 5/4730 Android Communications Intents, callbacks, and setters.
Services A Service is an application component that can perform long-running operations in the background and does not provide a user interface. An application.
Maps Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing.
Android Application Lifecycle and Menus
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
Lecture 2: Android Concepts
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors Date: Feb 11, 2016.
Cosc 4735 LocationAware API. Previous on … Before we looked at GPS location. – d-gpslocation.pptx
Cosc 5/4735 Voice Actions Voice Interactions (API 23+)
Location Based Services. Android location APIs make it easy for you to build location-aware applications, without needing to focus on the details of the.
Speech Service & client(Activity) 오지영.
Location based services 1. Some location-based services available in Android Geo-coding – Address -> location Reverse geo-coding – Location -> address(es)
1. 2 Android location services Determining a device’s current location Tracking device movements Proximity alerts.
CS499 – Mobile Application Development Fall 2013 Location & Maps.
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors
Lecture 5: Location Topics: Google Play Services, Location API
Location Services: Part 1 (Location and Geocoding)
Introduction to android
Google VR (gvr) CardBoard and DayDream With OpenGL
Android Application -Architecture.
Concurrency in Android
Lecture 5: Location Topics: Google Play Services, Location API.
Broadcast receivers.
Android – Event Handling
Android Location Based Services
Android 20: Location Kirk Scott.
Sensors, maps and fragments:
Picasso Revisted.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android: Preferences and user settings data
Activities and Intents
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Lecture 5: Location Topics: Google Play Services, Location API.
Android Developer Fundamentals V2 Lesson 5
Mobile Programming Dr. Mohsin Ali Memon.
SE4S701 Mobile Application Development
Activities and Fragments
Activities, Fragments, and Intents
CIS 470 Mobile App Development
Mobile Programming Broadcast Receivers.
CIS 694/EEC 693 Android Sensor Programming
External Services CSE 5236: Mobile Application Development
Presentation transcript:

Lecture 5: Location Topics: Google Play Services, Location API Date: Feb 16, 2016

References (study these) Read Everything Skim Codes Not-shown

Two API Options 1.Android API (not rich enough) 2.Google Play Services Location API (better) Tracking Geofencing Activity Recognition (walking, biking, driving …)

Making Your App Location Aware 0. Setup Google Play/Dependencies/Permissions… 1.Getting Last Known Location Usually the same as the current location 2.Changing Location Settings Detect and apply system settings for location features 3.Receiving Location Updates Request and received periodic location updates 4.Displaying a Location Address Converting long/lat to an address (reverse geocoding) 5.Creating and Monitoring Geofences Defining and dealing with geofences and user locations

0. Setup Google Play Location Services 1 1.Install Google Play Services SDK Manager > SDK Tools Select Google Play Services, Check, Apply. 2.Edit build.gradle (Module:app) Add new dependency and Sync. 3.Specify permission in AndroidManifest.xml Add new dependency and Sync. compile 'com.google.android.gms:play-services:8.4.0' 1 For more details – Setting Up Google Play Services:

Google Play Services – Basics

Google Play Services – Basics BobTheChairBuilder.addSawTool().addLog().build() build() add()

Google Play Services – Basics GoogleApiClientBuilder.addConnectionCallback().addConnectionFailedListener().addApi().build() implements ConnectionCallbacks implements ConnectionFailedListener API GoogleApiClient

Google Play Services – Basics GoogleApiClientBuilder.addConnectionCallback().addConnectionFailedListener().addApi().build() API GoogleApiClient connect() disconnect() ConnectionCallbacks onConnected() onConnectionSuspended() OnConnectionFailedListener onConnectionFailed()

1. Getting Last Known Location Step 1: Build a GoogleApiClient public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{ private GoogleApiClient c = protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (c == null) { c = new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); } public void onConnected(Bundle bundle) public void onConnectionSuspended(int i) public void onConnectionFailed(ConnectionResult connectionResult) {} }

1. Getting Last Known Location Step 2: connect() and disconnet() GoogleApiClient public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{ private GoogleApiClient c = protected void onCreate(Bundle savedInstanceState) { // code omitted (see last slide) public void onConnected(Bundle bundle) public void onConnectionSuspended(int i) public void onConnectionFailed(ConnectionResult connectionResult) protected void onStart() { c.connect(); super.onStart(); protected void onStop() { c.disconnect(); super.onStop(); } }

1. Getting Last Known Location Step 3: Get the location from public void onConnected(Bundle bundle) { try { Location loc = LocationServices.FusedLocationApi.getLastLocation(c); Log.v(“LOC", "" + loc.getLatitude() + ", " + loc.getLongitude()); }catch (SecurityException ex) { ex.printStackTrace(); } }

Code Practice 1.Setup App (Google Play Location Services etc.) 2.Connect to the Location Service 3.Print the location: lat/long 4.Show the location on a map (using Intent)

2. Set Up a Location Request Your Location App Your Location App Preferred Rate Max Rate Priority App #1 Pref: 100 ms Max: 20 ms App #1 Pref: 100 ms Max: 20 ms App #2 Pref: 50 ms Max: 30 ms App #2 Pref: 50 ms Max: 30 ms Question: What do you think Android does? (lat, long)

2. Set Up a Location Request Your Location App Your Location App Preferred Rate Max Rate Priority (lat, long) PriorityAccuracyPowerApproach PRIORITY_BALANCED_POWER_ACCURACY100m (block)LowWiFi+Cell PRIORITY_HIGH_ACCURACYGPS PRIORITY_LOW_POWER10 km (city)Low PRIORITY_NO_POWER-NegligibleOther apps “Potential Research Topic”

2. Set Up a Location Request Step 1: Create a LocationRequest object Step 2: Check current settings. Step 3: Prompt the user to change settings. LocationRequest req = new LocationRequest(); req.setInterval(10000); //preferred rate req.setFastestInterval(5000); //max rate it can handle req.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

3. Receive Location Updates public class MainActivity extends ActionBarActivity implements ConnectionCallbacks, OnConnectionFailedListener, LocationListener public void onLocationChanged(Location location) { //do something with the location } } Step 1: Implement LocationListener interface Step 2: Start and stop listening! LocationServices.FusedLocationApi.requestLocationUpdates( c, req, this); LocationServices.FusedLocationApi.removeLocationUpdates( c, this); onPause() onResume()

4. Displaying a Location Address Geocoder getFromLocation()Input: Output: , :”1100 N Carolina 54” 1:"Chapel Hill, NC 27516“ 2:"USA" getFromLocationName()Input: Output: Sitterson Hall 0:"UNC Sitterson Hall", 1:"Chapel Hill, NC 27514", 2:"USA" ….

Goecoder converts Lat/Long to an Address 4. Displaying a Location Address Geocoder g = new Geocoder(this, Locale.getDefault()); try { List la = g.getFromLocation(location.getLatitude(), location.getLongitude(), 1); Log.v("Address", la.get(0).toString()); }catch (Exception ex) { } Warning: This may take a long time. Use a background service or AsyncTask or a Thread.

Geofencing combines awareness of the user's current location with awareness of the user's proximity to locations that may be of interest. 5. Geofencing Lat, Long, and Radius (m) 100 geofences per device user Events: Entry Exit Dwell (specify duration) Expiration (ms) Use: Advertisement Coupons Avoid dangerous area

Code Practice 1.Get location updates (lat, long) 2.Print the Address!