Location-Based Services. Objectives How to display Google Maps in your application How to control displayed maps How to perform geocoding and reverse.

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

Bruce Scharlau, University of Aberdeen, 2010 Android and Location Mobile Computing Unless otherwise stated, images are from android sdk.
Location based services
CS378 - Mobile Computing Maps. Using Google Maps Like other web services requires an API key from Google ons/google-apis/mapkey.html.
Chapter 11: Discover! Incorporating Google Maps
Location-Based Services: Part 2 (Google Maps)
Google Android Map API Presentation 13/03/2008. Map API – Overview (1) Map rendering facility on Android device Similar to Google Earth Integrate map.
Location & Maps.  Mobile applications can benefit from being location-aware, e.g.,  Routing from a current to a desired location  Searching for stores.
Absolute Location.
Mapping.
CS378 - Mobile Computing Location.
CS378 - Mobile Computing Maps. Using Google Maps Content on using Google Maps inside your app Alternatives: Open Street Maps –
Map Applications.
Route Tracker App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Programming with Android: The Google Maps Library Slides taken from Luca Bedogni Marco Di Felice.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Google Maps Android API v2 吳俊興 國立高雄大學 資訊工程學系 CSF645 – Mobile Computing 行動計算
Location Services: Part 1 (Location and Geocoding)
Exploring Map Layers in Google Earth Georeferencing Images.
Location based services Using Google Maps v2 etc. in Android apps 1Location based services.
Location based services
CSS216 MOBILE PROGRAMMING Android, Chapter 8 Book: “Professional Android™ 2 Application Development” by Reto Meier, 2010 by: Andrey Bogdanchikov (
Lines of Latitude and Longitude
LATITUDE AND LONGITUDE
Android Accessing GPS Ken Nguyen Clayton State University 2012.
Longitude and Latitude
Location. GPS Global Positioning System – At least 4 satellites typically used 3 required extra for error detection and altitude typically accurate within.
Maps Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
Adding Location Nasrullah. Adding Location Adding a Map Activity Obtaining a Map API Debug Key Adding a Map View Finding an Address with Google’s GeoCoder.
Locating Positions on the Earth’s Surface
Sensors – Part 2 SE 395/595. Location in Android LocationManager class – Configure providers and their listeners LocationListener class – Handles update.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
Chapter 6 Google Play Services GOALS & OBJECTIVES Google Play Services give you features to attract users using Google features such as Google Maps, Google+,
Lecture 5: Location Topics: Google Play Services, Location API Date: Feb 16, 2016.
Location based services 1. Some location-based services available in Android Geo-coding – Address -> location Reverse geo-coding – Location -> address(es)
CS371m - Mobile Computing Maps. Using Google Maps Content on using Google Maps inside your app Alternatives Exist: – Open Street Maps –
CS378 - Mobile Computing Location (Location, Location, Location)
1. 2 Android location services Determining a device’s current location Tracking device movements Proximity alerts.
CS499 – Mobile Application Development Fall 2013 Location & Maps.
Get Microsoft Mouse Mischief
Location And Maps Sisoft Technologies Pvt Ltd
Lecture 5: Location Topics: Google Play Services, Location API
Get Microsoft Mouse Mischief
Android Application Maps 1.
Lecture 5: Location Topics: Google Play Services, Location API.
Location-Based Services: Part 2 (Google Maps)
TITLE-: SEARCH FOR ANY LOCATION USING GOOGLE MAPS
What this activity will show you
AnDroid GoogleMaps API
Tracking and Booking Taxi
Sensors, maps and fragments:
The GoogleMap API By Cody Littley.
CS371m - Mobile Computing Maps.
Latitude and Longitude
Latitude and Longitude
CIS 470 Mobile App Development
Maps and Map Skills.
Programming with Android: The Google Maps Library
Latitude and Longitude
Mapping the schoolyard geographically
Find your friend – An Android application
Latitude and Longitude
CIS 470 Mobile App Development
Lecture 5: Location Topics: Google Play Services, Location API.
Latitude and Longitude
CS378 - Mobile Computing Location and Maps.
Maps, Geocoding, and Location-Based Services.
CS 240 – Advanced Programming Concepts
Mobile Programming Dr. Mohsin Ali Memon.
Presentation transcript:

Location-Based Services

Objectives How to display Google Maps in your application How to control displayed maps How to perform geocoding and reverse geocoding How to obtain geographical data using GPS, Cell-ID, and Wi-Fi How to monitor for a location 2

Location-Based Services (LBS) Customize services based on one's location Track one's location and offer additional services such as locating nearby amenities, as well as offering suggestions for route planning. How? Use Google Maps API (v2 or above) Providing: com.google.android.gms.maps.MapView (ViewGroup) com.google.android.gms.maps.MapFragment (Fragment) com.google.android.gms.maps.GoogleMap Display a map with data obtained from the Google Maps service (need Internet permission) Control the map (using the GoogleMap class) Draw a number of overlays (e.g., markers) 3

Configuring Development Environment Google Maps Android API distributed as part of the Google Play services SDK Need to acquire API key from Google API Console Provide the SHA1 fingerprint of the signing certificate To test use: Android device (with Google Play services) or AVD with Google APIs (Google Inc), level 17 (4.2 Jelly Bean) or above 4

In-Class: Hello Earth Displaying a Google map 1.Install the Google Play services SDK Tools > Android > SDK Manager [SDK tools tab] 2.Create a new project Application name: Hello Earth Company domain: cs4330.cs.utep.edu Minimum SDK: API 17 Android 4.2 (Jelly Bean) Choose Google Maps Activity 3.Follow the direction in value/google_maps_api.xml Visit the link provided to get a Google Maps API key Note the finger print of your debugging certificate and the package name Add the API key to the google_maps_key entry of the xml file 5

Displaying Maps Use MapFragment or MapView class* Specify API key and other permissions in manifest Also need the INTERNET permission and others 6 <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyDIx1qJ2Uvds1585Wp1UiLiNZfprAfjlcU"/>... *from com.google.android.gms.maps package

7 In layout file <fragment android:layout_width=“match_parent" android:layout_height=“match_parent" class="com.google.android.gms.maps.MapFragment" /> or <com.google.android.gms.maps.MapView android:layout_width=“match_parent" android:layout_height=“match_parent" android:clickable="true"/>

8 In MainActivity If MapView is used, forward all the lifecycle methods such as onCreate and onResume from the Activity, e.g., protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MapView mapView = (MapView) findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); //-- needed! }

Zooming In/Out Programmatically Use GoogleMap.animateCamera(CameraUpdate) methods GooleMap: main class of Google Maps API and entry point for all methods related to the map CameraUpdate: define a camera move 9 GoogleMap map = mapView.getMap(); map.animateCamera(CameraUpdateFactory.zoomIn()); map.animateCamera(CameraUpdateFactory.zoomOut()); map.animateCamera(CameraUpdateFactory.zoomTo(4.0)); // zoom level: 2.0 ~ 21.0 map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

Changing Views Map modes (or views) Map: drawing of streets and places of interest Satellite: tiles of aerial imagery with roads and names superimposed Use GoogleMap.setMapType(int) MAP_TYPE_NORMAL: basic map with roads MAP_TYPE_SATELLITE: satellite view with roads MAP_TYPE_TERRAIN: terrain view with roads GoogleMap map = mapView.getMap(); map.setMapType(MAP_TYPE_SATELLITE); 10

Changing Views (Cont.) Can also display color-coded traffic conditions Use GoogleMap.setTrafficEnabled(boolean) Toggle traffic layer on or off Green: smooth traffic (50 miles/hour) Yellow: moderate (25-50 miles/hour) Red: slow (25 miles/hour) 11

Latitude And Longitude Grid system of the earth Latitude: run horizontally, 0-90* (degree) north and south from equator (1 degree = about 69 miles) Longitude: run vertically, 0-180* east and west from Greenwich (1 degree = about 69 miles) Degrees further divided into minutes (', 1/60 deg) and seconds (", 1/60 min) E.g., UTEP CCS Building 31*46'03"N 106*30'06"W 12

Latitude And Longitude (Cont.) Use com.google.android.gms.model.LatLng Immutable class representing a pair of latitude and longitude, stored as double numbers in degree API LatLng(double, double) public fields: latitude and longitude 13

Navigating To Specific Locations Use GoogleMap.animateCamera(CameraUpdate) animateCamera(CameraUpdateFactory.newLatLng(new LatLng(x,y))); or CameraUpdateFactory.newLatLngZoom(LatLng, float) Q: Navigate to UTEP CCS Building at 31*46'03.79"N 106*30'06.26"W ( , in degrees)? 14

Adding Markers Can add markers to a map to indicate places of interest How? Use GoogleMap.addMarker(MarkerOption), e.g., GoogleMap map =... // get a map. map.addMarker(new MarkerOptions().position(new LatLng( , )).title("UTEP CCS").snippet("Has Starbucks!").icon(BitmapDescriptorFactory.defaultMarker( BitmapDescriptorFactory.HUE_AZURE))); Define a new overlay, a set of images which are displayed on top of the base map tiles; refer to: TitleOverlay GoogleMap.addTitleOverlay(TitleOverlayOptions) 15

Screen vs. Geo Coordinates Getting the location that was touched? To know the latitude and longitude of a location corresponding to a position on the screen E.g., to determine a location's address, a process known as "reverse How? Override the onTouchEvent(MotionEvent) of the View class to obtain the screen location Use the Projection class to translate between on screen location and geographic coordinates on the surface of the Earth (LatLng). Projection GoogleMap.getProjection() APIs: LatLng fromScreenLocation(Point) Point toScreenLocation(LatLng) 16

(Reverse) Geocoding Geocoding Address to location (latitude and longitude) Use android.location.Address class Reverse geocoding Location to address Use android.location.Geocoder class 17 double Address.getLatitude() double Address.getLongiude() addresses.get(0).getLatitude() addresses.get(0).getLongitude() List getFromLocation(double, double, int) List getFromLocationName(String, int) List addresses = geoCoder.getFromLocation(latitude, longitude, 1); // 1: no. of results

Getting Location Data Several ways to identify your locations: GPS, cell tower triangulation, and Wi-Fi Use android.location.LocationManager class, providing access to the system location service Need permissions such as: android.permission.ACCESS_FINE_LOCATION android.permission.ACCESS_COARSE_LOCATION 18

19 lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, // minTime interval for notification, in miliseconds 0, // minDistance distance between location updates, in meters new LocationListener() {... }}; Several variations requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)... LocationListener interface void onLocationChanged(Location) void onProviderDisabled(String) void onProviderEnabled(String) void onStatusChanged(String, int, Bundle)

In-Class (Pair): Are We There? Trace the current location by placing a marker (say, an image of a car or a person) on a map and show a toast message upon arriving at the destination location. Develop incrementally P1: Place a marker at a certain location P2: Trace current location by moving the marker P3: Check if the marker is near the destination Q: How to detect if one is within a certain distance (in miles)? A: Use Location.distanceBetween method, e.g., float result = 0; final float[] dist = new float[1]; Location.distanceBetween(lat1, lng1, lat2, lng2, dist); result = dist[0] * f; // coz dist[0] is in meters 20