Location-Based Services: Part 2 (Google Maps)

Slides:



Advertisements
Similar presentations
Google Android Introduction to Mobile Computing. Android is part of the build a better phone process Open Handset Alliance produces Android Comprises.
Advertisements

Android Application Development Tutorial. Topics Lecture 4 Overview Overview of Sensors Programming Tutorial 1: Tracking location with GPS and Google.
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.
Location-Based Services: Part 2 (Google Maps)
Debugging Android Applications
Android Development (Basics)
Data Storage: Part 1 (Preferences)
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
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.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Google Maps Android API v2 吳俊興 國立高雄大學 資訊工程學系 CSF645 – Mobile Computing 行動計算
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.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
Cosc 5/4735 YouTube API. YouTube The YouTube Android Player API enables you to incorporate video playback functionality into your Android applications.
Events. Slide 2©SoftMoore Consulting Events Events are generated when a user interacts with the view objects of an application. Examples –button clicked–
Chapter 6 Google Play Services GOALS & OBJECTIVES Google Play Services give you features to attract users using Google features such as Google Maps, Google+,
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
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
Location-Based Services. Objectives How to display Google Maps in your application How to control displayed maps How to perform geocoding and reverse.
Introduction to Android Programming
Lecture 5: Location Topics: Google Play Services, Location API
Lab7 – Appendix.
Introduction to android
Google VR (gvr) CardBoard and DayDream With OpenGL
Permissions.
Android Programming - Features
Android Mobile Application Development
Android Application Maps 1.
Android Application Development 1 6 May 2018
Lecture 5: Location Topics: Google Play Services, Location API.
GUI Programming Fundamentals
Chapter 2 Starting a Project
AnDroid GoogleMaps API
Android – Event Handling
Android Studio, Android System Basics and Git
2D Graphics: Part 2.
MAD.
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.
Mobile Application Development BSCS-7 Lecture # 11
Customizing your device experience with assigned access
Mobile Device Development
CS371m - Mobile Computing Maps.
CIS 470 Mobile App Development
Programming with Android: The Google Maps Library
CMPE419 Mobile Application Development
Android Developer Fundamentals V2 Lesson 1
Activities and Intents
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Lecture 5: Location Topics: Google Play Services, Location API.
Mobile Programming Gestures in Android.
Android Project Structure, App Resources and Event Handling
CMPE419 Mobile Application Development
CS 240 – Advanced Programming Concepts
Mobile Programming Dr. Mohsin Ali Memon.
External Services CSE 5236: Mobile Application Development
Mobile Programming Broadcast Receivers.
CIS 694/EEC 693 Android Sensor Programming
External Services CSE 5236: Mobile Application Development
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 (a.k.a., Google Maps Android API v2) Google Maps Android API 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 an earlier version of Google Maps API. ©SoftMoore Consulting

Google Maps Android API Using Google Maps Android API, 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

Download Google Repository (Android SDK Manager) ©SoftMoore Consulting

Getting Started Make sure that Google Repository is installed, as shown in the previous slide. 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 greatly simplifies the middle three steps. ©SoftMoore Consulting

Creating a New Application with a Google Maps Activity 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. ©SoftMoore Consulting

Example: google_maps_api.xml (in src/debug/res/values) <resources> <!-- TODO: Before you run your application, you need a Google Maps API key. To get one, follow this link, follow the directions and press "Create" at the end: https://console.developers.google.com/flows/enableapi ... You can also add your credentials to an existing key, using these values: ... SHA-1 certificate fingerprint: C9:95:96:58:E5:7C:58:32:FC:B8:0F:2D:9F:CD:5C:CF:94:BC:54:E4 (continued on next slide) ©SoftMoore Consulting

Example: google_maps_api.xml (in src/debug/res/values) Alternatively, follow the directions here: https://developers.google.com/maps/documentation/android... Once you have your key (it starts with "AIza"), replace the "google_maps_key" string in this file. --> <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">YOUR_KEY_HERE</string> </resources> A sample key looks like “AIzaSyCNs7mQEGMgQG…” (39 characters) ©SoftMoore Consulting

Restrict the Key’s Use to Android Apps To improve your application’s security, you should restrict the key’s usage to “Android apps” in the API Console. A link to the API Console is provided when you obtain a key. To restrict the keys usage you will need to provide the package name and the SHA-1 signing certificate fingerprint from your keystore. The SHA-1 certificate fingerprint is displayed in the file google_maps_api.xml. Alternatively, the SHA-1 certificate fingerprint can be obtained by running the following command on the keystore: keytool -list -v -keystore debug.keystore debug.keystore is the name of the default keystore, usually in directory C:\Users\username\.android (password is android) ©SoftMoore Consulting

Test the Application Note: By default the Google Maps Activity does not contain an app 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. (This is done for you if you create a Google maps activity in Android Studio.) ©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: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="edu.citadel.android.googlemaps.MapsActivity" map:uiCompass="true" map:uiZoomControls="true"/> Note: This map fragment includes zoom controls and a compass. ©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 googleMap) 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 AppCompatActivity implements OnMapReadyCallback { ... // set to true if permission is granted private boolean isAccessLocationGranted = false; private GoogleMap mMap; ©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); checkAccessLocationPermission(); } Or use class SupportMapFragment and method getSupportFragmentManager() ©SoftMoore Consulting

Implementing the OnMapReadyCallback Interface (continued) Implement the onMapReady() method. @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; // Add a marker in Charleston and move the camera LatLng charleston = new LatLng(32.781, -79.935); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom (charleston, 14)); if (isAccessLocationGranted) try mMap.setMyLocationEnabled(true); } (continued on next slide) ©SoftMoore Consulting

Implementing the OnMapReadyCallback Interface (continued) catch (SecurityException ex) { String errorMsg = getString(R.string.no_permission); Log.e(LOG_TAG, errorMsg, ex); } mMap.addMarker(new MarkerOptions() .title("Charleston, S.C.") .snippet("The most beautiful city in North America.") .position(charleston)); ©SoftMoore Consulting

Requesting User Permissions In order to call map.setMyLocationEnabled(true), user permission to access the user’s location must be declared in the Android manifest file and requested at runtime. Example <manifest ... >   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>     ... </manifest> ©SoftMoore Consulting

Google Map Example (continued) Moves map to current location. Using two fingers to rotate the map will enable the compass. ©SoftMoore Consulting

Creating a Virtual Device for Google Maps Make sure that Google Play Services and the Google Repository are installed as described earlier 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

Relevant Links Getting Started Google Maps Android API https://developers.google.com/maps/documentation/android-api/start Google Maps Android API https://developers.google.com/maps/documentation/android-api/ Set Up Google Play Services https://developers.google.com/android/guides/setup Map Objects https://developers.google.com/maps/documentation/android-api/map Sign Your App https://developer.android.com/studio/publish/app-signing.html Google Maps Sample Project <android-sdk>/extras/google/google_play_services/samples/maps ©SoftMoore Consulting