Chapter 11: Discover! Incorporating Google Maps

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

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.
Chapter 3: Engage! Android User Input, Variables, and Operations
Programming with Android: SDK install and initial setup Luca Bedogni Marco Di Felice Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna.
Prepared by: Prepared by: Jameela Rabaya Jameela Rabaya Fatima Darawsha Fatima Darawsha.
Chapter 6: Jam! Implementing Audio in Android Apps.
© 2010 Delmar, Cengage Learning Chapter 1 Getting Started with Dreamweaver.
CS378 - Mobile Computing Maps. Using Google Maps Like other web services requires an API key from Google ons/google-apis/mapkey.html.
Location & Maps.  Mobile applications can benefit from being location-aware, e.g.,  Routing from a current to a desired location  Searching for stores.
Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department.
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
Android Tutorial Larry Walters OOSE Fall References This tutorial is a brief overview of some major concepts…Android is much richer and more complex.
CST JavaScript Validating Form Data with JavaScript.
CS378 - Mobile Computing Maps. Using Google Maps Content on using Google Maps inside your app Alternatives: Open Street Maps –
Map Applications.
Chapter 1: Voilà! Meet the Android. Smartphones –Can browse the Web –Allow you to play games –Use business applications –Check –Play music –Record.
Route Tracker App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 9: Customize! Navigating with a Master/Detail.
Adobe Dreamweaver CS3 Revealed CHAPTER ONE: GETTING STARTED WITH DREAMWEAVER.
Hands-On Microsoft Windows Server 2008
Google Maps Android API v2 吳俊興 國立高雄大學 資訊工程學系 CSF645 – Mobile Computing 行動計算
Chapter 12: Finale! Publishing Your Android App. Objectives In this chapter, you learn to: Understand Google Play Target various device configurations.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
Chapter 9: Customize! Navigating with Tabs on a Tablet App.
Chapter 1: Voilà! Meet the Android
Chapter 10: Move! Creating Animation
Social network Twitter Hashtag: #m2eu #android Personal Israel Ferrer –
Location based services
Chapter 2: Simplify! The Android User Interface
PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse 
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 5: Investigate! Android Lists, Arrays,
DUE Hello World on the Android Platform.
Chapter 12: Finale! Publishing Your Android App
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Presented By: Muhammad Tariq Software Engineer Android Training course.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
Engage! Android User Input, Variables,
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 7: Reveal! Displaying Pictures in a GridView.
Android Boot Camp for Developers Using Java, 3E
Chapter 7: Reveal! Displaying Pictures in a Gallery.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Chapter Two Creating a First Project in Visual Basic.
MAKANI ANDROID APPLICATION Prepared by: Asma’ Hamayel Alaa Shaheen.
Maps Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
Adding Overlay Items.  So, now you have a map, but in many cases you'll also want to create your own map markers and lay-overs.  You must implement.
First Venture into the Android World Chapter 1 Part 2.
Webview and Web services. Web Apps You can make your web content available to users in two ways in a traditional web browser in an Android application,
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
TODAY Android Studio Installation Getting started Creating your 1 st App Beginning to understanding Intents.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 10: Move! Creating Animation 1 Android.
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.
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.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
CS499 – Mobile Application Development Fall 2013 Location & Maps.
Chapter 2: Simplify! The Android User Interface
Android Application Maps 1.
Location-Based Services: Part 2 (Google Maps)
Android Studio, Android System Basics and Git
Sensors, maps and fragments:
Microsoft Office Illustrated Fundamentals
Presentation transcript:

Chapter 11: Discover! Incorporating Google Maps

Objectives In this chapter, you learn to: Create an Android project displaying a Google map Install the Google API to the SDK Set up a Google API Android Virtual Device Locate your MD5 certificate Sign up for a Google Maps API key Understand security and permissions Android Boot Camp for Developers using Java

Objectives (continued) Access the MapView class Code the populate( ) method Add the onTap( ) method Set permissions for maps in the Android Manifest file Create a GeoPoint overlay Android Boot Camp for Developers using Java

Using Google Maps Smartphones can access online maps using a built-in Android Google Maps application Users can zoom in to see details Can be customized Figure 11-1 Maps Application Android Boot Camp for Developers using Java

Using Google Maps (continued) Steps to complete the App: Install the Google API add-on to the SDK. Add the AVD that uses the Google API deployment target. Obtain a personal Maps API key from Google. Define a MapView inside a Linear layout in main.xml. Add permissions to the Android Manifest file to access the Internet and the Google library. Add a no title bar theme to the Android Manifest file. Add the pushpin image to the drawable folder. Code the MapView in Main.java. Add Overlay objects to the map. Call the populate( ) method to read each Overlay object. Display two GeoPoint overlays. Android Boot Camp for Developers using Java

Using Google Maps (continued) Google Maps is a Free online mapping service offering things like: Turn-by-turn directions GPS Location Services Directions to a hotel Distance of a morning run Street view images Bike path directions Possible Traffic delays Public transit routes Began in the United States in 2005 Updated Frequently Android Boot Camp for Developers using Java

Installing the Google API API – Application Programming Interface A set of tools for building software applications Downloading, rendering, and caching of map files Must be downloaded and installed in your SDK environment Figure 11-3 Android SDK Manager Android Boot Camp for Developers using Java

Installing the Google API (continued) Adding the AVD to Target the Google API Android Virtual Device (AVD) must be set to use the Google API Figure 11-4 Android Virtual device Manager dialog box Android Boot Camp for Developers using Java

Installing the Google API (continued) Figure 11-6 Google API displayed in the AVD list Figure 11-5 Create new Android Virtual Device (AVD) dialog box Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google Must apply for a free Google Maps API key Register and agree to terms with Google Maps Service Your computer’s MD5 (Message-Digest Algorithm 5) digital fingerprint verifies the integrity of the file A unique Google Maps API key is generated: Certificate fingerprint (MD5): 94:1E:43:49:87:73:BB:E6:A6:88:D7:20:F1:8E:B5:98 Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google (continued) You cannot run a Google Map app if it is not signed with your local API key. Key is stored in a file named debug.keystore Figure 11-7 Location of the debug.keystore file on a Windows 7 computer Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google (continued) Figure 11-8 MD5 fingerprint in the Command Prompt window Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google (continued) Troubleshooting: Keytool not recognized You need to locate the keytool executable file on your computer A fingerprint other than MD5 is generated A fingerprint such as SHA1 might appear instead of the MD5 fingerprint Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google (continued) Registering the MD5 Fingerprint with the Google Maps Service A single Maps API key is valid for all applications signed by a single certificate Place theMD5 fingerprint in the Google Registration page You need a Gmail account to receive the API key Place the API key in the XML layout code http://developers.google.com/android/maps-api-signup Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google (continued) Figure 11-10 Android Maps API Key Signup Web Site Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google (continued) Figure 11-11 Unique MD5 fingerprint code Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google (continued) Figure 11-12 Android Maps API key Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google (continued) Adding the MapView element in the XML Code API key attribute holds the Google Maps API key that proves your application and signed certificate are registered with the Google Maps service the API key must be added to the main.xml layout file You must use the <com.google.android.maps.MapView/> element to display the Google Maps in your Activity Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google (continued) <com.google.android.maps.MapView android:id="@ +id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey="0HljqLj_jO8oBj4g8zSxyEuezie5-mE_56_UiXA“ /> Note: Your generated apiKey will be different. Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google (continued) Adding Permissions to the Android Manifest File Permissions are necessary to prevent malicious outside applications from corrupting data and accessing sensitive information including: Full access to the Internet Your GPS location Your personal information Phone calls SMS Messages Other system tools Android Boot Camp for Developers using Java

Obtaining a Maps API Key from Google (continued) Figure 11-16 Android Manifest code with the Google library permission Android Boot Camp for Developers using Java

Understanding MapView The MapView class displays and manipulates a Google Map The setBuiltInZoomControls property allows the site visitor to use the built-in zoom feature MapView mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); Android Boot Camp for Developers using Java

Understanding MapView (continued) Figure 11-19 Main Extends MapActivity Figure 11-20 Instance of MapView and the zoom controls set to true Android Boot Camp for Developers using Java

Understanding MapView (continued) Figure 11-21 Google Maps displayed in the Android emulator Android Boot Camp for Developers using Java

Adding Overlay Items Overlays – also called Map markers – use a graphic image to indicate a specific location on a map Use the ItemizedOverlay class to manage the individual items placed as a layer on the map Android Boot Camp for Developers using Java

Adding Overlay Items (continued) Figure 11-22 Overlay.java class Android Boot Camp for Developers using Java

Adding Overlay Items (continued) Figure 11-23 Overlay.java class automated code Android Boot Camp for Developers using Java

Adding Overlay Items (continued) Adding Overlay Objects to an ArrayList Assign an expandable array called ArrayList Customized constructors needed to define default markers Populate() method used to add each pushpin item to the display Android Boot Camp for Developers using Java

Adding Overlay Items (continued) private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); private Context mContext; public Overlay(Drawable defaultMarker, Context context) { super(boundCenterBottom(defaultMarker)); mContext = context; // TODO Auto-generated constructor stub } public void addOverlay(OverlayItem overlay) { mOverlays.add(overlay); populate(); @Override protected OverlayItem createItem(int i) { // TODO Auto-generated method stub return mOverlays.get(i); public int size() { return mOverlays.size(); Android Boot Camp for Developers using Java

Adding Overlay Items (continued) Figure 11-25 Overlay constructor Android Boot Camp for Developers using Java

Adding Overlay Items (continued) Figure 11-26 The addOverlay method populates the pushpin images Android Boot Camp for Developers using Java

Adding Overlay Items (continued) Figure 11-27 OverlayItem method Android Boot Camp for Developers using Java

Adding Overlay Items (continued) Coding the onTap Method onTap() method receives the index of the overlay item selected by the user The AlertDialog box displays a message to the user The show() method is actually used to display the dialog box @Override protected boolean onTap(int index) { OverlayItem item = mOverlays.get(index); AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); dialog.setTitle(item.getTitle()); dialog.setMessage(item.getSnippet()); dialog.show(); return true; } Android Boot Camp for Developers using Java

Adding Overlay Items (continued) Figure 11-29 onTap() method Android Boot Camp for Developers using Java

Adding Overlay Items (continued) Figure 11-30 Instance named item and the AlertDialog box are coded Android Boot Camp for Developers using Java

Adding Overlay Items (continued) Figure 11-31 Complete code of Overlay.java Android Boot Camp for Developers using Java

Adding Overlay Items (continued) Coding the Drawable Overlay Figure 11-32 List of Overlay items Figure 11-33 The pushpin image becomes the map marker Android Boot Camp for Developers using Java

Locating a GeoPoint Default Google map is of the United States Any worldwide location can be found by panning and zooming Map location – called the GeoPoint – contains latitude and longitude coordinates GeoPoint locations are in microdegrees (degrees * 1e6) For example, Lynchburg Virginia’s latitude and longitude coordinates are 37.4198°, -79.14°, which yields coordinates of 37419800, -79140000 microdegrees Android Boot Camp for Developers using Java

Locating a GeoPoint (continued) Coding the GeoPoint Location Figure 11-35 First GeoPoint Android Boot Camp for Developers using Java

Locating a GeoPoint (continued) Figure 11-36 Second GeoPoint Android Boot Camp for Developers using Java

Locating a GeoPoint (continued) Figure 11-37 Main.java complete code Android Boot Camp for Developers using Java

Summary To use Google Maps, you must install the Google API (application programming interface) in the Android SDK and then embed the Google Maps site directly into an Android application and overlay app-specific data on the map Set the application’s properties to select the Google APIs add-on as the build target, which sets the Android Virtual Device (AVD) Manager to use the new Google API You need to apply for a free Google Maps API key to integrate Google Maps into your Android application Android Boot Camp for Developers using Java

Summary (continued) Using the MD5 fingerprint, you can register with Google for aMaps API key at the onlineGoogleMaps service. To display a Googlemap in an Android app, you must add the API key to the main.xml layout file in your project You must use the <com.google.android.maps.MapView> element to display the Google Maps in your Activity Android Boot Camp for Developers using Java

Summary (continued) Android apps use permissions to prevent malicious outside applications from corrupting data and accessing sensitive information. Apps need permission to access the Internet and connect with the Google mapping feature Google mapping technology relies on the Android MapView class Android Boot Camp for Developers using Java

Summary (continued) An instance of MapView uses the setBuiltInZoomControls property. When set to true, this property allows site visitors to use the built-in zoom feature on the map in your Android app A map marker, or overlay, uses a graphic image such as a pushpin to indicate a specific location on a map The Overlay class assigns an ArrayList to hold the overlay objects, such as pushpin images, displayed in a layer on the map Android Boot Camp for Developers using Java

Summary (continued) Use the populate( ) method to add each new item in the ItemizedOverlay to the map Use the onTap() method to display a text message Use an instance of the MapView class to list points of interest Users can pan and zoom to find any location in the world from the default USA map GeoPoints contain latitude & longitude coordinates Use the add( ) method to display the GeoPoints as an overlay on the map Android Boot Camp for Developers using Java