1 / 12

Google Maps Android API v2

CSF645 – Mobile Computing 行動計算. Google Maps Android API v2. 吳俊興 國立高雄大學 資訊工程學系. https://developers.google.com/maps/documentation/android/. Introduction to the Google Maps Android API v2. The API automatically handles access to Google Maps servers data downloading map display, and

cayla
Télécharger la présentation

Google Maps Android API v2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSF645 – Mobile Computing行動計算 Google Maps Android API v2 吳俊興 國立高雄大學 資訊工程學系 https://developers.google.com/maps/documentation/android/

  2. Introduction to the Google Maps Android API v2 • The API automatically handles • access to Google Maps servers • data downloading • map display, and • response to map gestures • 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

  3. Google Maps Android API v2 Improvements • Distributed as part of the Google Play services SDK • Encapsulated in the MapFragment class, an extension of Android's Fragment class, rather in the Activity class • Able to add a map as a piece of a larger Activity • Able to implement them by extending the Android standard Activity class, rather than extending the MapActivity used in version 1 • Using vector tiles: data representation is smaller, with less bandwidth • Caching is improved, so users will typically see a map without empty areas. • Supporting 3D maps

  4.  Overall Process of Adding a Map to an App • Step 1. Download and configure the Google Play services SDK • The Google Maps Android API is distributed as part of this SDK • Step 2. Obtain an API key • To do this, you will need to register a project in the Google APIs Console, and get a signing certificate for your app • Step 3. Specify settings in the Application Manifest • Step 4. Add a map to a new or existing Android project • Run the Sample Code - com.example.mapdemo https://developers.google.com/maps/documentation/android/start

  5. Run the Sample Code - com.example.mapdemo • Make sure Google Play services added as an Android library project • Select File > Import > Android > Existing Android Code Into Workspace and click Next • Select Browse..., enter <share>/google-play-services_lib, and click Finish • View the sample code, or run the sample app locally • Sample code is bundled with the Google Play services SDK • Select File > Import > Android > Existing Android Code Into Workspace and click Next. • Select Browse..., enter <android-sdk-folder>/extras/google/google_play_services/samples/maps, and click Finish • Select Project > Properties, select Java Build Path, and navigate to Libraries. • Select Add External Jars, include the following jar files, and click OK: + <android-sdk-folder>/extras/android/support/v4/android-support-v4.jar • Add your own Google Maps Android API key • Select Run > Run to test the sample app

  6. Step 1. Setup Google Play Services SDK • To develop an app using the Google Play services APIs, download the Google Play services SDK from the SDK Manager • The download includes the client library and code samples • To test your app when using the Google Play services SDK, you must use either: • A compatible Android device that runs Android 2.2 or higher and includes Google Play Store • The Android emulator with an AVD that runs the Google APIs platform based on Android 4.2.2 or higher • Three steps: • S1-1. Install the Google Play Services SDK • S1-2. Set Up a Project with the Library • S1-3. Ensure Devices Have the Google Play services APK http://developer.android.com/google/play-services/setup.html

  7. S1-1. Install the Google Play Services SDK • Launch the SDK Manager • From Eclipse (with ADT), select Window > Android SDK Manager • Install the Google Play services SDK • Saved in <android-sdk>/extras/google/google_play_services/ • Install a compatible version of the Google APIs platform • To test app on the emulator, expand the directory for Android 4.2.2 (API 17) or a higher version, select Google APIs, and install it • Make a copy of the Google Play services library project • Copy the library project at <android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/ to the location where you maintain your Android app projects (i.e. adt-bundle/share) • import the library project into your workspace. Click File > Import, select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it

  8. S1-2. Set Up a Project to UseGoogle Play Services SDK • Reference the library project in your Android project • Make sure that both the project library and the application project that depends on it are in your workspace. If one of the projects is missing, import it into your workspace • In the Package Explorer, right-click the dependent project and select Properties • In the Properties window, select the "Android" properties group at left and locate the Library properties at right • Click Add to open the Project Selection dialog • From the list of available library projects, select a project and click OK • When the dialog closes, click Apply in the Properties window • Click OK to close the Properties window

  9. Step 2. Obtain an API Key • The Google Maps Android API v2 uses a new system of managing keys • Existing keys from a Google Maps Android v1 application, commonly known as MapView, will not work with the v2 API • Obtain a Maps API key from the Google APIs Console by providing the application's signing certificate and its package name • Once having the key, add it to the application by adding an element to the application's manifest file AndroidManifest.xml • Maps API keys are linked to specific certificate/package pairs • Sign each of your applications with a different certificate and get a different key for each one • Four steps: • S2-1: Retrieve information about your application's certificate • S2-2: Register a project in the Google APIs Console and add the Maps API as a service for the project • S2-3: Once you have a project set up, you can request one or more keys Add your key to your application and begin development

  10. S2-1. Displaying Certificate Information • An app has two certificates • Debug certificate: only for use with an application for testing • Release certificate • SHA-1 fingerprint: a short form of application's digital certificate • Eclipse goes to Windows > Preferences > Android > Build

  11. S2-2. Obtaining an API Key • Go to https://code.google.com/apis/console/ • API Project > Services: Enable Google Maps Android API v2 • API Project > API Access >  Create New Android Key.... • Enter the SHA-1 fingerprint, then a semicolon, then your application's package name • The Google APIs Console responds by displaying Key for Android apps (with certificates) followed by a forty-character API key • Copy this key value AIzaSyDZVhi1AFAqVN6djSpXLq36dvljPSeVFGU

  12. S2-3. Adding the API Key to the Application • In AndroidManifest.xml, add the following element as a child of the <application> element, by inserting it just before the closing tag </application>: <meta-dataandroid:name="com.google.android.maps.v2.API_KEY"android:value="your_api_key"/> substituting your API key for your_api_key. This element sets the key com.google.android.maps.v2.API_KEY to the valueyour_api_key and makes the API key visible to any MapFragment in your application. • Add the following elements to your manifest. Replace com.example.mapdemo with the package name of your application. <permissionandroid:name="com.example.mapdemo.permission.MAPS_RECEIVE"android:protectionLevel="signature"/><uses-permissionandroid:name="com.example.mapdemo.permission.MAPS_RECEIVE"/> • Save AndroidManifest.xml and re-build your application.

More Related