Location-Based Services: Part 2 (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

Programming with Android: SDK install and initial setup Luca Bedogni Marco Di Felice Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna.
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.
Chapter 11: Discover! Incorporating Google Maps
Lecture 13 Mobile Programming Google Maps Android API.
Filip Debelić What is it? Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google Android,
Android: Hello World Frank Xu Gannon University. Steps Configuration ▫Android SDK ▫Android Development Tools (ADT)  Eclipse plug-in ▫Android SDK and.
Debugging Android Applications
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
Android Development (Basics)
INTERNATIONAL SUMMER ACADEMIC COURSE UNIVESITY OF NIS ISAC – Android programming.
Android Application Development 2013 PClassic Chris Murphy 1.
CS378 - Mobile Computing Maps. Using Google Maps Content on using Google Maps inside your app Alternatives: Open Street Maps –
Data Storage: Part 1 (Preferences)
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
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.
Microsoft Visual Basic 2012 CHAPTER TWELVE (ENRICHMENT CHAPTER) Windows Store Apps.
Programming with Android: The Google Maps Library Slides taken from Luca Bedogni Marco Di Felice.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 9: Customize! Navigating with a Master/Detail.
Chapter 3 Navigating a Project Goals & Objectives 1.Get familiar with the navigation of the project. How is everything structured? What settings can you.
Google Maps Android API v2 吳俊興 國立高雄大學 資訊工程學系 CSF645 – Mobile Computing 行動計算
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
Web Technologies Website Development Trade & Industrial Education
Mobile Programming Lecture 16 The Facebook API. Agenda The Setup Hello, Facebook User Facebook Permissions Access Token Logging Out Graph API.
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,
Cosc 5/4730 Introduction: Threads, Android Activities, and MVC.
Basic Android Tutorial USF’s Association for Computing Machinery.
Website Development with Dreamweaver
© 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.
Overview of Android Application Development
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
© 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.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
Maps Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
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,
ANDROID APPLICATION DEVELOPMENT. ANDROID DEVELOPMENT DEVELOPER.ANDROID.COM/INDEX.HTML THE OFFICIAL SITE FOR ANDROID DEVELOPERS. PROVIDES THE ANDROID SDK.
USING HARDWARE DEVICES When building a mobile application, it's important that you always test your application on a real device before releasing it.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
Intoduction to Andriod studio Environment With a hello world program.
Cosc 5/4735 YouTube API. YouTube The YouTube Android Player API enables you to incorporate video playback functionality into your Android applications.
Google map v2.
GOOGLE PLAY By William Cook April 14, GOOGLE PLAY Marketplace for apps for android Androids “app store” You must make an account on the developer.
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.
CS371m - Mobile Computing Maps. Using Google Maps Content on using Google Maps inside your app Alternatives Exist: – Open Street Maps –
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CHAPTER 1 part 1 Introduction. Chapter objectives: Understand Android Learn the differences between Java and Android Java Examine the Android project.
Introduction to Android Programming
Lab7 – Appendix.
Google VR (gvr) CardBoard and DayDream With OpenGL
Android Application Maps 1.
Location-Based Services: Part 2 (Google Maps)
GUI Programming Fundamentals
Chapter 2 Starting a Project
Android Studio, Android System Basics and Git
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Sensors, maps and fragments:
The GoogleMap API By Cody Littley.
Programming with Android: The Google Maps Library
CMPE419 Mobile Application Development
Android Developer Fundamentals V2 Lesson 1
CMPE419 Mobile Application Development
CS 240 – Advanced Programming Concepts
Mobile Programming Dr. Mohsin Ali Memon.
Presentation transcript:

Location-Based Services: Part 2 (Google Maps)

Accessing Google Maps Google maps can be accessed in two ways Through a browser or a WebView Through the Google Maps Android API v2 Google Maps Android API v2 allows you to incorporate Google Maps into applications is distributed as part of the Google Play Services SDK encapsulates maps in a MapFragment or a SupportMapFragment MapFragment and SupportMapFragment essentially replace the MapActivity class used in version 1. ©SoftMoore Consulting

Google Maps Android API v2 Using Google Maps Android API v2, you can Add maps to your app 3D maps − terrain maps satellite maps − etc. Customize the map markers − image overlays polylines/polygons − etc. Control the user’s view zoom − pan rotate − etc. ©SoftMoore Consulting

Attribution Requirements If you use the Google Maps Android API in your application, you must include the Google Play Services attribution text as part of a “Legal Notices” section in your application. Including legal notices as an independent menu item, or as part of an “About” menu item, is recommended. The attribution text is available by making a call to method GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo() ©SoftMoore Consulting

Getting Started Download and configure the Google Play services SDK, which includes the Google Maps Android API. Obtain a Google Maps API key. register a project in the Google APIs Console get a Google Maps key associated with the signing certificate and package for your app Add the required settings in your application’s manifest. Add a map to your application. Test your application Android Studio helps simplify the middle three steps. ©SoftMoore Consulting

Download Google Play Services (Android SDK Manager) ©SoftMoore Consulting

Creating a New Application with a Google Maps Activity Make sure that the Google Play services SDK is installed, as shown in previous slide. Using Android Studio, start with a Google Maps Activity when creating a new project or add a Google Maps Activity to an existing project. The resource google_maps_api.xml contains the information and steps needed to obtain a Google Maps API key. The slides at the end of this section provide the details needed to add Google Maps to an application if you do not create a Google Maps Activity in Android Studio. ©SoftMoore Consulting

Test the Application Note: By default the Google Maps Activity does not contain an action bar. ©SoftMoore Consulting

Map UI Properties Similar to other Android UI properties, most map UI properties can be set using one of two approaches declarative (in an XML file) procedural approach (in the Java code). As usual, the declarative approach is generally preferred. ©SoftMoore Consulting

Classes MapFragment and SupportMapFragment Classes MapFragment and SupportMapFragment (in package com.google.android.gms.maps) are the simplest ways to place a map in an application. Use SupportMapFragment if you need to support Android devices running API 10 and lower. These classes wrap a view of a map that automatically handles the necessary life cycle needs. Add a MapFragment or a SupportMapFragment to an activity’s layout file. ©SoftMoore Consulting

Selected XML Attributes for a MapFragment mapType values include none, normal, hybrid, satellite, and terrain uiZoomControls, uiCompass specify whether you want the zoom controls and compass to appear on the map uiZoomGestures, uiScrollGestures, etc. specify which gestures are enabled/disabled liteMode map that supports a subset of the map functionality Add these attributes using the following namespace declaration: xmlns:map="http://schemas.android.com/apk/res-auto" ©SoftMoore Consulting

SupportMapFragment Example <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/map" tools:context=".MapsActivity" android:name="com.google.android.gms.maps.SupportMapFragment" map:uiZoomControls="true" /> Note: This map fragment includes zoom controls. ©SoftMoore Consulting

Class GoogleMap GoogleMap models the map object within an application. GoogleMap automatically handles Connecting to the Google Maps service. Downloading map tiles. Displaying tiles on the device screen. Displaying various controls such as pan and zoom. Responding to pan and zoom gestures by moving the map and zooming in or out. ©SoftMoore Consulting

The OnMapReadyCallback Interface The OnMapReadyCallBack interface contains a single abstract method. public void onMapReady(GoogleMap map) Implement the OnMapReadyCallback interface to get access to a GoogleMap object. Use the GoogleMap object to set map properties. ©SoftMoore Consulting

Implementing the OnMapReadyCallback Interface Import the necessary map classes and interfaces. import com.google.android.gms.maps.*; import com.google.android.gms.maps.model.*; Declare that the activity implement the interface. public class MainActivity extends ActionBarActivity implements OnMapReadyCallback ©SoftMoore Consulting

Implementing the OnMapReadyCallback Interface (continued) Use getMapAsync() to set the callback on the map fragment. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); } Or use class SupportMapFragment and method getSupportFragmentManager() ©SoftMoore Consulting

Implementing the OnMapReadyCallback Interface (continued) Implement the onMapReady() method. @Override public void onMapReady(GoogleMap map) { LatLng charleston = new LatLng(32.781, -79.935); map.setMyLocationEnabled(true); map.moveCamera(CameraUpdateFactory .newLatLngZoom(charleston, 14)); map.addMarker(new MarkerOptions() .title("Charleston, S.C.") .snippet("The most beautiful city in North America.") .position(charleston)); } ©SoftMoore Consulting

Google Map Example (continued) ©SoftMoore Consulting

Creating a Virtual Device for Google Maps Make sure that you have installed (using the Android SDK manager) a Google APIs system image for the virtual device target. Make sure that the virtual device target supports Google APIs; i.e., the phrase “Google APIs” should appear somewhere in the target name. ©SoftMoore Consulting

Creating a Virtual Device for Google Maps (continued) ©SoftMoore Consulting

Creating a Virtual Device for Google Maps (continued) ©SoftMoore Consulting

Adding Google Maps to an Application The remaining slides in this section provide the details needed to add Google Maps to an application if you do not create a Google Maps Activity in Android Studio. ©SoftMoore Consulting

Setting Up Google Play Services (https://developer. android Make sure that the Google Play services SDK is installed, as shown in previous slide. In Android Studio under “Gradle Scripts”, edit the build.gradle file for “Module: app” (not the build.gradle file for the project) Under dependencies (near the bottom), add the following line at the end: compile 'com.google.android.gms:play-services-maps:6.5.+' Also add this line if you are combining maps with other location services such as location updates. compile 'com.google.android.gms:play-services-location:6.5.+' ©SoftMoore Consulting

Setting Up Google Play Services (continued) Save the changes and click “Sync Project with Gradle Files” in the toolbar, or click on menu item Tools  Android  Sync Project with Gradle Files. Edit file AndroidManifest.xml and add the following tag as a child of the <application> element: <meta-data android:name="com.google.android.gms.version"        android:value="@integer/google_play_services_version"/> Note: You can ignore instructions about creating a ProGuard exception if you are building in debug mode (i.e., not release mode). ©SoftMoore Consulting

Obtaining a Maps API Key Before using the Google Maps service, you need to obtain a Google Maps API key. If you created a Google Maps Activity using Android Studio, then the resource google_maps_api.xml contains the information and steps needed to obtain a Google Maps API key. Otherwise you must Use your certificate’s SHA1 fingerprint to register with the Maps service to obtain a Maps API key Include the Maps API key in MapView elements of the XML layout files Sign the application with the same certificate used to obtain the Maps API key ©SoftMoore Consulting

The SDK Debug Key Recall that during installation, the Android SDK tools create a debug keystore and key in <ANDROID_SDK_HOME>\.android with predetermined names/passwords: Keystore name: “debug.keystore” Keystore password: “android” Key alias: “androiddebugkey” Key password: “android” At each compilation, the SDK tools use this debug key to sign the .apk file. ©SoftMoore Consulting

Obtaining the Debug Key’s SHA1 Fingerprint Use Java’s keytool “- list” option to obtain the certificate’s SHA1 fingerprint. Example C:\Java\Android\sdk\android-sdk\.android>keytool –list -keystore debug.keystore Enter keystore password: Keystore type: JKS Keystore provider: SUN Your keystore contains 1 entry androiddebugkey, Dec 14, 2014, PrivateKeyEntry, Certificate fingerprint (SHA1): 37:97:13:32:E7:57:08:56:9A:E7:51:CB:43:B3:... all on one line (enter “android”) response ©SoftMoore Consulting

Register with the Google Maps Service to Obtain a Maps API Key To get a Google Maps API key, go to https://developers.google.com/maps/documentation/android/start Scroll to “Create an API project in the Google APIs Console” and follow instructions to register your project for the Maps API. Then scroll to “Obtain a Google Maps API key” and follow the instructions to obtain an API key. You will need to enter the certificate’s fingerprint and one or more package names; e.g., 37:97:13:32:E7:57:08:56:9A:E7:...;edu.citadel.android.maps ©SoftMoore Consulting

Register with the Google Maps Service to Obtain a Maps API Key (continued) When submitted, you will get back a page with an API key that can be used for apps signed with your certificate: following information; e.g., something like AIzaSyBI6yPiqwvpUH8_X7w_HNE2yiHhpDuUD58 ©SoftMoore Consulting

Configure the Application’s Manifest Add the following element as a child of the <application> element: <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyBI6yPiqwvpUH8_X7w_HNE2yiHhpDuUD58"/> Specify permissions; e.g., android.permission.INTERNET android.permission.ACCESS_NETWORK_STATE android.permission.WRITE_EXTERNAL_STORAGE android.permission.ACCESS_FINE_LOCATION Use your Maps API key here. (or COARSE_LOCATION) ©SoftMoore Consulting

Configure the Application’s Manifest (continued) Recommended: To prevent Google Play Store from displaying the app on devices that don't support OpenGL ES version 2, add the following element as a child of the <manifest> element: <uses-feature android:glEsVersion="0x00020000" android:required="true"/> ©SoftMoore Consulting

Create Simple Test App Create a basic new project in Android Studio, and replace the layout file (activity-main.xml) with the following: <?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.MapFragment" /> ©SoftMoore Consulting

Test the Simple App ©SoftMoore Consulting

Relevant Links Google Maps Android API v2 https://developers.google.com/maps/documentation/android/ Setting Up Google Play Services https://developer.android.com/google/play-services/setup.html Map Objects https://developers.google.com/maps/documentation/android/map Signing Your Applications http://developer.android.com/tools/publishing/app-signing.html Google Maps Sample Project <android-sdk>/extras/google/google_play_services/samples/maps ©SoftMoore Consulting