Map Applications.

Slides:



Advertisements
Similar presentations
Android Application Development A Tutorial Driven Course.
Advertisements

Android Application Development Tutorial. Topics Lecture 4 Overview Overview of Sensors Programming Tutorial 1: Tracking location with GPS and Google.
Google APIs & Location Based Applications -Krishna Achanta
Bruce Scharlau, University of Aberdeen, 2010 Android and Location Mobile Computing Unless otherwise stated, images are from android sdk.
Connect Pictometry Online End User
Introducing to Location in Android LOCATION IS EVERYTHING Kamil Lelonek Kamil Lelonek
Location based services
Joemarie Comeros Amparo Android Development Orientation for Starters.
Prepared by: Prepared by: Jameela Rabaya Jameela Rabaya Fatima Darawsha Fatima Darawsha.
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
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.
GPS and MapView. First In the emulator, set the time zone to something (e.g., east coast) and check that the time is correct. Otherwise, the gps emulator.
Location and Maps Content Getting Location Getting Google Map In application Test on Emulator/Device.
Cosc 5/4730 GPS/Location android.location. Simulator notes All the simulators can simulator GPS/location information – Android DDMS commands (geo) to.
CS378 - Mobile Computing Location.
Android Tutorial Larry Walters OOSE Fall References This tutorial is a brief overview of some major concepts…Android is much richer and more complex.
INTERNATIONAL SUMMER ACADEMIC COURSE UNIVESITY OF NIS ISAC – Android programming.
CS378 - Mobile Computing Maps. Using Google Maps Content on using Google Maps inside your app Alternatives: Open Street Maps –
Android Sensors & Async Callbacks Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
Route Tracker App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
About me Yichuan Wang Android Basics Credit goes to Google and UMBC.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Mobile Application Development Selected Topics – CPIT 490
Google Maps Android API v2 吳俊興 國立高雄大學 資訊工程學系 CSF645 – Mobile Computing 行動計算
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
CS5103 Software Engineering Lecture 08 Android Development II.
Location-Based API 1. 2 Location-Based Services or LBS allow software to obtain the phone's current location. This includes location obtained from the.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
Location Services: Part 1 (Location and Geocoding)
Location based services Using Google Maps v2 etc. in Android apps 1Location based services.
Social network Twitter Hashtag: #m2eu #android Personal Israel Ferrer –
Location based services
CSS216 MOBILE PROGRAMMING Android, Chapter 8 Book: “Professional Android™ 2 Application Development” by Reto Meier, 2010 by: Andrey Bogdanchikov (
Take a leap towards the most promising technology
INTRODUCTION TO HTML5 Geolocation. Display a Specific Location with Google Maps  You can use the Google Maps API to display a custom map on your own.
DUE Hello World on the Android Platform.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
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
Context Aware Location Nasrullah. Location Basics LocationManager—Class providing access to Android system location services LocationListener—Interface.
Overview of Android Application Development
MAKANI ANDROID APPLICATION Prepared by: Asma’ Hamayel Alaa Shaheen.
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.
LocationListener in Android Nasrullah. The LocationManager provides access to the system location services The LocationListener is used for receiving.
Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing.
ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are.
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.
Cosc 4735 LocationAware API. Previous on … Before we looked at GPS location. – d-gpslocation.pptx
GPS and MapView. First In the emulator, set the time zone to something (e.g., east coast) and check that the time is correct. Otherwise, the gps emulator.
Android Fundamentals. What is Android Software stack for mobile devices Software stack for mobile devices SDK provides tools and APIs to develop apps.
CS371m - Mobile Computing Maps. Using Google Maps Content on using Google Maps inside your app Alternatives Exist: – Open Street Maps –
3 rd -party APIs Kalin Kadiev Astea Solutions AD.
1. 2 Android location services Determining a device’s current location Tracking device movements Proximity alerts.
Location-Based Services. Objectives How to display Google Maps in your application How to control displayed maps How to perform geocoding and reverse.
CS499 – Mobile Application Development Fall 2013 Location & Maps.
Android Application Maps 1.
Tracking device movements
Location-Based Services: Part 2 (Google Maps)
AnDroid GoogleMaps API
Tracking and Booking Taxi
Android Location Based Services
Sensors, maps and fragments:
תכנות ב android אליהו חלסצ'י.
CS371m - Mobile Computing Maps.
CS378 - Mobile Computing Location and Maps.
Maps, Geocoding, and Location-Based Services.
Presentation transcript:

Map Applications

Location Service Two main LBS elements Location Manager Location Manager: Provides hooks to the location-based services Location Providers: Each of these represents a different location- finding technology used to determine the device’s current location Location Manager Obtain current location Track movement Set proximity alerts for areas Find available Location Providers Location Providers Various location-finding technologies (GPS, Cellular network)

Android Software Stack

Global Positioning System (GPS)

Cell Tower Triangulation An alternative method to determine the location of a cell phone is to estimate its distance to three nearby cell towers. Distance of the phone to each antenna could be estimated based upon the lag time between the moment the tower sends a ping to the phone and receives the answering ping back. Quite similar to the 2D- Trilateration Method.

Latitude & Longitude Latitude in GPS-Decimal notation: +90.00000 (North) to -90.000000 (South) • Longitude GPS-Decimal notation: +180.000000 (East) to -180.000000 (West)

Latitude & Longitude

Android Location Classes The Android API provides Location data based on a variety of methods including: Cell Tower Triangulation, and most commonly GPS chip readings. GPS is the most common location provider on the Android based phones. It offers the most accuracy. Picture: Epson Infineon GPS (2.8 x 2.9mm)

Android Location Classes

Location Class A class representing a geographic location sensed at a particular time. A location consists of a latitude and longitude, a UTC timestamp and optionally information on altitude, speed, and bearing. Information specific to a particular provider or class of providers may be communicated to the application using getExtras, which returns a Bundle of key/value pairs. Each provider will only provide those entries for which information is available.

Location Values Format The three common formats: There are sixty seconds in a minute (60" = 1') and There are sixty minutes in a degree (60' = 1°). DDD° MM' SS.S” 32° 18' 23.1" N 122° 36' 52.5" W DDD° MM.MMM’ 32° 18.385' N 122° 36.875' W DDD.DDDDD° 32.30642° N or +32.30642 122.61458° W or -122.61458

Location Manager This class provides access to the system location services. These services allow applications To obtain periodic updates of the device's geographical location, or to fire an application-specified Intent when the device enters the proximity of a given geographical location. String service_name = Context.LOCATION_SERVICE; LocationManager locationManager = (LocationManager) getSystemService(service_name)

LocationProvider Class An abstract superclass for location providers. A location provider supplies periodic reports on the geographical location of the device. Each provider has a set of criteria under which it may be used; for example, some providers require GPS hardware and visibility to a number of satellites; others require the use of the cellular radio, or access to a specific carrier's network, or access to the internet. They may also have different battery consumption characteristics or monetary costs to the user. The Criteria class allows providers to be selected based on userspecified criteria.

LocationProvider Class Provider Reference String providerName = LocationManager.GPS_PROVIDER; LocationProvider gpsProvider; gpsProvider = locationManager.getProvider(providerName); Common Location Providers: LocationManager.GPS_PROVIDER LocationManager.NETWORK_PROVIDER Getting list of all providers boolean enabledOnly = true; List<String> providers = locationManager.getProviders(enabledOnly);

Finding Location Providers Using Criteria Provider with specific requirements Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(false); criteria.setCostAllowed(true); String bestProvider = locationManager.getBestProvider(criteria, true); To get all matching Providers List<String> matchingProviders = locationManager.getProviders(criteria, false);

LocationListener Class Used for receiving notifications from the LocationManager when the location has changed. These methods are called if the LocationListener has been registered with the location manager service using the method: requestLocationUpdates (Provider, minTime, minDistance, LocationListener)

LocationListener String provider = LocationManager.GPS_PROVIDER; int t = 5000; // milliseconds int distance = 5; // meters LocationListener myLocationListener = new LocationListener() { public void onLocationChanged(Location location) { // Update application based on new location. } public void onProviderDisabled(String provider) { // Update application if provider disabled. } public void onProviderEnabled(String provider) { // Update application if provider enabled.} public void onStatusChanged(String provider, int status, Bundle extras) {// Update application if provider hardware status changed.} }; locationManager.requestLocationUpdates(provider, t, distance, myLocationListener);

FINDING YOUR LOCATION Reference Location Manager String service_name = Context.LOCATION_SERVICE; LocationManager locationManager = (LocationManager) getSystemService(service_name) Permissions in Manifest <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> Last location “fix” String provider = LocationManager.GPS_PROVIDER; Location location = locationManager.getLastKnownLocation(provider);

Example – Obtain Location from GPS In this example we request GPS services and display latitude and longitude values on the UI. Notes Observe the GPS chip is not a synchronous device that will immediately respond to a “give me a GPS reading” call. In order to engineer a good solution that takes into account the potential delays in obtaining location data: we place the UI in the main activity and the request for location call in a background service. Remember the service runs in the same process space as the main activity, therefore for the sake of responsiveness: we must place the logic for location data request in a separate parallel thread.

Example – Obtain Location from GPS

Geocoding Geocoding lets you translate between street addresses and longitude/latitude map coordinates. The geocoding lookups are done on the server, so your applications will require you to include an Internet uses- permission in your manifest, as shown here: <uses-permission android:name="android.permission.INTERNET"/> The Geocoder class provides access to two geocoding functions: Forward geocoding Finds the latitude and longitude of an address Reverse geocoding Finds the street address for a given latitude and longitude

Reverse Geocoding location = locationManager.getLastKnownLocation (LocationManager.GPS_PROVIDER); double latitude = location.getLatitude(); double longitude = location.getLongitude(); List<Address> addresses = null; Geocoder gc = new Geocoder(this, Locale.getDefault()); try { addresses = gc.getFromLocation(latitude, longitude, 10); } catch (IOException e) {}

Forward Geocoding Geocoder fwdGeocoder = new Geocoder(this, Locale.US); String streetAddress = "160 Riverside Drive, New York, New York"; List<Address> locations = null; try { locations = fwdGeocoder.getFromLocationName(streetAddress, 10); } catch (IOException e) {}

Emulating GPS Location Use DDMS > Emulator Control

Google Maps External Library Android uses the Google Maps External Library to add mapping capabilities to your applications. Google Maps External Library includes the com.google.android.maps package. The classes of this package offer built-in downloading, rendering, and caching of Maps tiles, as well as a variety of display options and controls. The key class in the Maps package is com.google.android.maps.MapView, a subclass of ViewGroup. The MapView provides an ideal user interface option for presenting geographical data. Road View

MapViews MapViews support annotation using Overlays and by pinning Views to geographical locations. The Maps external library is not part of the standard Android library, so it may not be present on some compliant Android- powered devices. By default the Android SDK includes the Google APIs add-on, which in turn includes the Maps external library. MapViews offer full programmatic control of the map display, letting you control the zoom, location, and display modes — including the option to display satellite, street, and traffic views. Aerial View

Google Map Classes MapView is the Map View control. MapActivity is the base class you extend to create a new Activity that can include a Map View. MapActivity handles the application life cycle and background service management required for displaying maps. Map Views are used only within MapActivity-derived Activities. MapController is used to control the map, enabling you to set the center location and zoom levels. Overlay is the class used to annotate your maps. MyLocationOverlay is a special Overlay that can be used to display the current position and orientation of the device. ItemizedOverlays and OverlayItems are used together to let you create a layer of map markers, displayed using Drawables and associated text.

Creating a Map-Based Activity Manifest XML <uses-library android:name="com.google.android.maps"/> <uses-permission android:name="android.permission.INTERNET"/> Layout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.google.android.maps.MapView android:id="@+id/map_view" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey="mymapapikey" /> </LinearLayout>

MapActivity

Configuring and Using Map Views Specifying how the map is displayed. mapView.setSatellite(true); mapView.setStreetView(true); mapView.setTraffic(true); Querying the Map View. int maxZoom = mapView.getMaxZoomLevel(); GeoPoint center = mapView.getMapCenter(); int latSpan = mapView.getLatitudeSpan(); int longSpan = mapView.getLongitudeSpan(); • Optionally display the standard map zoom controls mapView.setBuiltInZoomControls(true);

Using the Map Controller Use the Map Controller to pan and zoom a MapView. getController get a reference to a MapView’s controller. MapController mapController = mapView.getController(); Map locations are represented by GeoPoint objects. Double lat = 37.422006*1E6; Double lng = -122.084095*1E6; GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue()); Re-center and zoom the Map. mapController.setCenter(point); mapController.setZoom(1); // 1=widest (or most distant), 21=tightest (nearest) view ‘‘jump’’ to a new location mapController.animateTo(point);

Creating and Using Overlays Overlays enable you to add annotations and click handling to MapViews. Each Overlay lets you draw 2D primitives, including text, lines, images, etc. All the Overlays assigned to a Map View are added as layers, with newer layers potentially obscuring older ones. User clicks are passed through the stack until they are either handled by an Overlay or registered as clicks on the Map View itself.

Creating New Overlays To add a new Overlay create a new class that extends Overlay. Override the draw method to draw the annotations you want to add, and override onTap to react to user clicks

The Projection class lets you translate between latitude/longitude coordinates (stored as GeoPoints) and x/y screen pixel coordinates (stored as Points). A map’s Projection may change between subsequent calls to draw, so it’s good practice to get a new instance each time. Projection projection = mapView.getProjection(); Use the fromPixel and toPixel methods to translate from GeoPoints to Points and vice versa. Point myPoint = new Point(); // To screen coordinates projection.toPixels(geoPoint, myPoint); // To GeoPoint location coordinates projection.fromPixels(myPoint.x, myPoint.y);

Drawing on the Overlay Canvas

Handling Map Tap Events The onTap handler receives two parameters: A GeoPoint that contains the latitude/longitude of the map location tapped The MapView that was tapped to trigger this event @Override public boolean onTap(GeoPoint point, MapView mapView) { // Perform hit test to see if this overlay is handling the click if ([ . . . perform hit test . . . ]) { //[ . . . execute on tap functionality . . . ] return true; } // If not handled return false return false;

Adding and Removing Overlays Each MapView contains a list of Overlays currently displayed. List<Overlay> overlays = mapView.getOverlays(); To add an Overlay onto a Map View, create a new instance of the Overlay and add it to the list Good practice to call postInvalidate after you modify the list to update the changes on the map display MyOverlay myOverlay = new MyOverlay(); overlays.add(myOverlay); mapView.postInvalidate(); projection.fromPixels(myPoint.x, myPoint.y);

My Location Overlay Special Overlay designed to show your current location and orientation on a MapView. List<Overlay> overlays = mapView.getOverlays(); MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView); overlays.add(myLocationOverlay); Can display both your current location (represented as a flashing blue marker) and your current orientation (shown as a compass on the map display). myLocationOverlay.enableCompass(); myLocationOverlay.enableMyLocation(); Stopping the service myLocationOverlay.disableCompass(); myLocationOverlay.disableMyLocation();

Google API Key To use the Google Map service an API key is needed. The API key can obtained as follows for development/debugging application: Get debug.keystore file. You can find the location to the file under “Default debug keystore” from: Windows ➪ Preferences ➪ Android ➪ build. Use keytool tool to generate Certificate fingerprint (MD5). Use following command on command prompt keytool -list -alias androiddebugkey -keystore <keystore_location>.keystore - storepass android -keypass android Go to ‘Sign Up for the Android Maps API‘ page. Put your Certificate fingerprint (MD5) And get your API key for android GMap application. Replace “mymapapikey” in MapView layout item with your API key.