Lab 6: Google Maps Android API v2 Android Studio 10/14/2016

Similar documents
Google Maps library requires v2.50 or above.

Lecture 13 Mobile Programming. Google Maps Android API

1. Location Services. 1.1 GPS Location. 1. Create the Android application with the following attributes. Application Name: MyLocation

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Programming with Android: The Google Maps Library. Slides taken from

CS371m - Mobile Computing. Maps

Google Maps Troubleshooting

From time to time Google changes the way it does things, and old tutorials may not apply to some new procedures.

External Services. CSE 5236: Mobile Application Development Course Coordinator: Dr. Rajiv Ramnath Instructor: Adam C. Champion

Mobile Application Development Google Maps Android API

Android Programming วรเศรษฐ ส วรรณ ก.

BlackBerry Developer Global Tour. Android. Table of Contents

Upon completion of the second part of the lab the students will have:

Login with Amazon. Getting Started Guide for Android apps

Obtaining a Google Maps API Key. v1.0. By GoNorthWest. 15 December 2011

Mobile Programming Lecture 1. Getting Started

Assignment 1: Port & Starboard

TomTom Mobile SDK QuickStart Guide

CS378 -Mobile Computing. Maps

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

Introduction To Android


Lab 4 In class Hands-on Android Debugging Tutorial

Android Application Development using Kotlin

Hello World. Lesson 1. Create your first Android. Android Developer Fundamentals. Android Developer Fundamentals

Fragments and the Maps API

Getting Started with Android Development Zebra Android Link-OS SDK Android Studio

Android Programming - Jelly Bean

Create new Android project in Android Studio Add Button and TextView to layout Learn how to use buttons to call methods. Modify strings.

Perceptive SOAPBridge Connector

Programming with Android: Geo-localization and Google Map Services. Luca Bedogni. Dipartimento di Scienze dell Informazione Università di Bologna

Signing For Development/Debug

Android Workshop: Model View Controller ( MVC):

WebSphere Puts Business In Motion. Put People In Motion With Mobile Apps

12 Publishing Android Applications

Course Syllabus. Course Title. Who should attend? Course Description. Android ( Level 1 )

ATC Android Application Development

Android Application Development. By : Shibaji Debnath

Android InsecureBankv2 Usage Guide. InsecureBankv2

Introduction to Android

Installing and configuring an Android device emulator. EntwicklerCamp 2012

SD Module-1 Android Dvelopment

Azure Developer Immersion Getting Started

Lab 01 How to Survive & Introduction to Git. Web Programming DataLab, CS, NTHU

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2.

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Wireless Vehicle Bus Adapter (WVA) Android Library Tutorial

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface?

Building MyFirstApp Android Application Step by Step. Sang Shin Learn with Passion!

APPENDIX. Application User. MainActivity.java. RegistrationActivity.java

32. And this is an example on how to retrieve the messages received through NFC.

CS371m - Mobile Computing. Persistence - Web Based Storage CHECK OUT g/sync-adapters/index.

IEMS 5722 Mobile Network Programming and Distributed Server Architecture

Screen Slides. The Android Studio wizard adds a TextView to the fragment1.xml layout file and the necessary code to Fragment1.java.

Android Programming Lecture 2 9/7/2011

GUJARAT TECHNOLOGICAL UNIVERSITY

BlackBerry Developer Summit. A02: Rapid Development Leveraging BEMS Services and the AppKinetics Framework

Developing Android applications in Windows

Supporting Android Devices

ArcGIS Runtime SDK for Android: Building Apps. Shelly Gill

Monday schedule on Tuesday Great time to work with team on Course Project

Table of Content. CLOUDCHERRY Android SDK Manual

Salesforce Classic Mobile User Guide for Android


<uses-permission android:name="android.permission.internet"/>

CMSC436: Fall 2013 Week 4 Lab

Minds-on: Android. Session 1

CLEO VLTrader Made Simple Guide

Tutorial on OpenCV for Android Setup

Tutorial on Basic Android Setup

Android Programming Lecture 8: Activities, Odds & Ends, Two New Views 9/28/2011

API Signup Instructions

Lab 1: Getting Started With Android Programming

Our First Android Application

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Android App Development

University of Stirling Computing Science Telecommunications Systems and Services CSCU9YH: Android Practical 1 Hello World

ArcGIS Runtime SDK for Android An Introduction. Xueming

Software Practice 3 Before we start Today s lecture Today s Task Team organization

COMP4521 EMBEDDED SYSTEMS SOFTWARE

android-espresso #androidespresso

Supporting Android Devices

Guide to Deploying VMware Workspace ONE. VMware Identity Manager VMware AirWatch 9.1

Getting Started With Android Feature Flags

Adobe Marketing Cloud Bloodhound for Mac 3.0

COSC 3P97 Mobile Computing

ANDROID SYLLABUS. Advanced Android

Debojyoti Jana (Roll ) Rajrupa Ghosh (Roll ) Sreya Sengupta (Roll )

Family Map Client Specification

BUILD AND DEPLOY SOA PROJECTS FROM DEVELOPER CLOUD SERVICE TO ORACLE SOA CLOUD SERVICE

Lab 3: Using Worklight Server and Environment Optimization Lab Exercise

Hitachi ID Systems Inc Identity Manager 8.2.6

CALIFORNIA STATE UNIVERSITY WIN GPS. A Project. Presented to the. Faculty of. California State University, San Bernardino. In Partial Fulfillment

AT&T Global Network Client for Android

Nextiva Drive The Setup Process Mobility & Storage Option

Computer Science E-76 Building Mobile Applications

Guide to Deploying VMware Workspace ONE with VMware Identity Manager. SEP 2018 VMware Workspace ONE

ELET4133: Embedded Systems. Topic 15 Sensors

Corporate Infrastructure Solutions for Information Systems (LUX) ECAS Mockup Server Installation Guide

Transcription:

Lab 6: Google Maps Android API v2 Android Studio 10/14/2016 One of the defining features of mobile phones is their portability. It's not surprising that some of the most enticing APIs are those that enable you to find, contextualize, and map physical locations. Using the external Maps library included as part of the Google API package, you can create map-based Activities using Google Maps as a user interface element. You have full access to the map, which enables you to control display settings, alter the zoom level, and pan to different locations. Using Overlays you can annotate maps and handle user input. The API automatically handles access to Google Maps servers, data downloading, map display, and response to map gestures. You can also use API calls to add markers, polygons, and overlays to a basic map, and to change the user's view of a particular map area. These objects provide additional information for map locations, and allow user interaction with the map. References: https://developers.google.com/maps/documentation/android/intro https://developers.google.com/maps/documentation/android/start http://developer.android.com/google/play-services/index.html Meier, Reto. Professional Android 4 Application Development Map Fragment/Map View Quick Start:https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl- AE9fjbJySowONZZtNHzw In this hands-on lab we are going create a basic Google Maps Android API v2 App Note: You will not be able to fully test your Google Maps Android API v2 App using an Android emulator. It's not supported except for mock locations. If you do not have a device, try to get one or find a partner. See deliverables on page 11. Attribution: If you use the Google Maps Android API in your application, you are required 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: GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo. Jay Urbain, Ph.D. 1

1) Setup Google Play services SDK (Android Studio) Open up the SDK Manager, scroll to the bottom, expand Extras ; select, accept, and download: Google Play Services Google Repository Reference: http://developer.android.com/google/play-services/index.html Android Studio Create a new Android project: Jay Urbain, Ph.D. 2

When adding an activity, make your life a lot easier, and select Google Maps Activity: Jay Urbain, Ph.D. 3

Google Maps API Key Your application needs an API key to access the Google Maps servers. The key is free, and you can use it with any of your applications that call the Google Maps Android API. It supports an unlimited number of users. The easiest way to get a key is to use the link provided in the google_maps_api.xml file that Android Studio created for you. Copy the link provided in the google_maps_api.xml file and paste it into your browser. The link takes you to the Google Developers Console and supplies information via URL parameters, thus reducing the manual input required from you. Follow the instructions to create a new project on the console or select an existing project. Create Studio, and paste the API key into the <string> element in the google_maps_api.xml file. Jay Urbain, Ph.D. 4

Your key should be automatically added to your manifest. You can also just enter your key here directly. The following dependency is added to your gradle.build file. You will need to remember this if you add Maps functionality to an existing project. Jay Urbain, Ph.D. 5

Notes: Adding credentials from scratch (not required for this lab) You can also use the credentials provided in the google_maps_api.xml file that Android Studio created for you, and use the copied credentials to add your app to an existing API key, or to create a new API key. Go to the Google Developer s console: https://console.developers.google.com/. All Android apps are signed with a digital certificate for which you hold the private key. Android API keys are linked to specific certificate/package pairs. You only need one key for each certificate, no matter how many users you have for the app. Getting a key for your app requires several steps: 1. Get information about your app's certificate. 2. Register a project in the Google Developers Console and add the Google Maps Android API as a service for the project. 3. Create a key. 4. Add the key to your app by adding an element to your app manifest. The full process for getting an API key, and creating a key from scratch are defined here: https://developers.google.com/maps/documentation/android-api/signup Go to the appendix of this document for step-by-step instructions for creating a keystore and adding it and Google services to your App. Note: Very important!!! If you change anything that has to do with your API key, clean and re-sync your project, and uninstall any previous version from your phone. Jay Urbain, Ph.D. 6

Examine the template code XML layout file for your activity; res/layout/activity-maps.xml layout <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.supportmapfragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.jayurbain.mapsdemo2016.mapsactivity" /> Jay Urbain, Ph.D. 7

Maps Activity Java file: Note: Your code should look similar to the code below. package com.jayurbain.mapsdemo2016; import android.support.v4.app.fragmentactivity; import android.os.bundle; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.onmapreadycallback; import com.google.android.gms.maps.supportmapfragment; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.markeroptions; public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { private GoogleMap mmap; @Override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapfragment = (SupportMapFragment) getsupportfragmentmanager().findfragmentbyid(r.id.map); mapfragment.getmapasync(this); } } } /** * Manipulates the map once available. * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onmapready(googlemap googlemap) { mmap = googlemap; // Add a marker in Sydney and move the camera LatLng sydney = new LatLng(-34, 151); mmap.addmarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); mmap.movecamera(cameraupdatefactory.newlatlng(sydney)); Jay Urbain, Ph.D. 8

Run your App Connect your Android Device or use the Android Emulator to run your app. Use an x86 target AVD to improve performance. Jay Urbain, Ph.D. 9

Experiment/Deliverables 1) Change your default location to: 1025 N. Broadway Ave., Milwaukee WI, 53217 There are several freely available geocoding service on the web. Here s one: https://geoservices.tamu.edu/services/geocode/interactive/ 2) Add some form of additional functionality: change map type, use indoor maps, add custom markers, polylines, etc. You may want to add the Google demo apps: https://developers.google.com/maps/documentation/android-api/code-samples You will need to create a new API key corresponding to the application package: com.example.mapdemo: https://developers.google.com/maps/documentation/android-api/signup Additional documentation: https://console.developers.google.com/project https://developers.google.com/maps/documentation/android/map https://developers.google.com/maps/documentation/android/ https://developers.google.com/maps/documentation/android-api/?hl=en_us Submit report documenting your work, with snapshot, and feedback on the lab to Blackboard. Jay Urbain, Ph.D. 10

NOT Required!!! Appendix: Google Maps Android API utility library Download the android-maps-utils repository. You can do it by cloning the repo (recommended, to receive automatic updates) or downloading a zip file. If you want to customize the library, you should fork the repo. https://github.com/googlemaps/android-maps-utils Create working directory git init git clone Jay Urbain, Ph.D. 11

Appendix: Adding Google Play Services dependencies and creating debug or release keystores Once these packages have been installed, add the Google Play Services dependency and a reference to your debug.keystore to your projects build.gradle file. By default, there are two build files within the project structure; one within your modules directory (top one within app) and one within the project directory. Note: It is recommended that you replace the + version reference of your play-services with a specific reference. Note: I just use the + and have not had any trouble, so I would skip it. To identify your most recent version, navigate to the following directory within your SDK installation directory: com.google.android.gms:play-services and also check your target device. Jay Urbain, Ph.D. 12

Creating a key store: Build -> Generate Signed APK Select Create new debug keystore. Make sure you use the same key store path, key store password, key alias, and key password as your build.gradle file (second image below). Jay Urbain, Ph.D. 13

Generate your keys: Navigate to your debug.keystore directory. Run the following command in your terminal to generate your developer certificates SHA1 fingerprint key. Make sure you include alias, storepass, and keypass options. Note: If you can not find keytool, it is provided in the bin directory of your JDK installation. $ keytool -list -v -keystore debug.keystore -alias debugkeystore -storepass keystorepwd -keypass keystorepwd Example: jays-mbp:.android jayurbain$ keytool -list -v -keystore debug.keystore -alias debugkeystore -storepass keystorepwd -keypass keystorepwd Alias name: debugkeystore Creation date: Oct 25, 2014 Entry type: PrivateKeyEntry Certificate chain length: 1 Certificate[1]: Owner: CN=Jay Urbain, O=Upstream Development LLC, L=Bayside, ST=WI, C=53217 Issuer: CN=Jay Urbain, O=Upstream Development LLC, L=Bayside, ST=WI, C=53217 Serial number: 544c12c1 Valid from: Sat Oct 25 16:14:41 CDT 2014 until: Wed Oct 19 16:14:41 CDT 2039 Certificate fingerprints: MD5: 4A:2D:BE:E7:B9:54:0F:7B:00:B7:B2:FF:A9:34:30:EB SHA1: 7F:36:B0:D0:CD:2F:39:34:CA:97:A1:0B:7E:A1:5E:F0:B4:61:B4:83 Signature algorithm name: SHA1withRSA Version: 3 jays-mbp:.android jayurbain$ Make a copy of your SHA1. Jay Urbain, Ph.D. 14

Creating an API Key for your App Now that your project is set up, register your application in the Google Developer Console to allow it access to the Play Services API. Navigate to https://console.developers.google.com/project If needed, create a new project. After creating this project, click it and then select APIs & auth from the left hand menu. From the list of APIs that appear, scroll down and ensure that Google Maps Android API v2 is set to On. Jay Urbain, Ph.D. 15

Next, select Credentials from the left hand menu. Under the Public API access heading, click Create New Key, and then Android Key. Select, create new Key: Jay Urbain, Ph.D. 16

Take your SHA1 key, and append the apps package name to the end of it, separated by a semicolon. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.jayurbain.mymapapp" > Using the package name above, your string should look look like: 7F:36:B0:D0:CD:2F:39:34:CA:97:A1:0B:7E:A1:5E:F0:B4:61:B4:83;com.jayurbain.mymapapp Paste your key and package name into the textbox and click Create. You ll see an API generated and displayed on the page. Copy this key to your clipboard. Select create. Jay Urbain, Ph.D. 17

Jay Urbain, Ph.D. 18

Add the following the following uses-permission, and application meta-data tags to your AndroidManifest.xml as shown below. Remember to use your Google provided API key. Hand in there, we re getting close! Jay Urbain, Ph.D. 19

Appendix: Adding a Map to the View Open up your main activity xml layout file and declare your map view as a fragment, and then set it to load the contents of a map on app load. Set your layout as follows: Main activity: Jay Urbain, Ph.D. 20

Running the app now will load up the map and place a marker right in the middle of it. Holding down on the marker will allow you to drag and drop it around the map. Jay Urbain, Ph.D. 21

Appendix: Notes for running maps on an emulator (I have not tried this!) To run your app on an Emulator, Google Play Services needs to be installed. You can try the following if it is not already installed or if you are having trouble downloaded the services ( I did not verify this works) Download Two.apk Files 1. Google Play services apk: download the latest fromhttps://play.google.com/store/apps/details?id=com.google.android.gms using this apk downloader website http://apps.evozi.com/apk-downloader/ 2. Google Play store apk: http://www.androidpolice.com/2013/08/13/download-latestgoogle-play-store-4-3-11-teardown/ 4.4.22 was the latest at the time of writing this post. ( 3 ) Install the apks Files Use the following command to install the apk on the emulator. [location of apk file] >adb install com.google.android.gms.apk [location of apk file] >adb install com.android.vending-4.4.22.apk Jay Urbain, Ph.D. 22

Acknowledgement: This lab was developed by Jay Urbain Jay Urbain, Ph.D. 23