Configuring Android Applications to Use Google Maps
Go Up to Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
This topic explains how to configure your Android applications to use the TMapView component and Google Maps Android API.
The following subjects are covered:
- Getting Android API key
- Configuring specific project options
Contents
Getting Android API key
To access the Google Maps servers with Google Maps Android API, you have to add an Android API key to your application. This section outlines basic steps to get this key:
- Retrieve information about the certificate of your application.
- Register a project in the Google API Console and enable Google Maps Android API for that project.
- Set up Android API key.
Retrieving Your Application Certificate
The Maps API key is based on a short form of the digital certificate of your application, known as its SHA-1 fingerprint. The fingerprint is a unique text string generated from the commonly-used SHA-1 hashing algorithm. You may have certificates of two types: Debug certificate and Release certificate.
To display the debug certificate fingertip
- Locate the appropriate debug.keystore file. RAD Studio uses the debug.keystore file located into:
%Users%\<user name>\AppData\Roaming\Embarcadero\BDS\<version number>\
, for example:
C:\Users\JohnDoe\AppData\Roaming\Embarcadero\BDS\23.0\debug.keystore
- Tip: If you cannot find the debug.keystore file in the above mentioned location, run your application on the Android target platform, and then RAD Studio automatically creates this file.
-
Find the keytool.exe file. The
keytool
tool is available in<Java installation folder>\Bin
, for example:
C:\Program Files\Java\jdk1.7.0_71\bin\
. -
Switch to the folder where the debug.keystore file is located and run:
keytool -list -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android
- Tip: You need to add the full path to
keytool
; if the keytool.exe file is located in the example provided above, you can use the following:"C:\Program Files\Java\jdk1.7.0_71\bin\keytool" -list -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android
-
The
keytool
tool displays an output similar to this:Alias name: androiddebugkey Creation date: Jan 24, 2015 Entry type: PrivateKeyEntry Certificate chain length: 1 Certificate[1]: Owner: CN=Unnamed, OU=Mobile Organization, O=My Company, L=San Francisco, ST=California, C=US Issuer: CN=Unnamed, OU=Mobile Organization, O=My Company, L=San Francisco, ST=California, C=US Serial number: 1af9d77f Valid from: Sat Jan 24 23:12:12 GST 2015 until: Wed Jun 11 23:12:12 GST 2042 Certificate fingerprints: MD5: 20:E1:7D:12:4F:83:2A:37:FB:F5:43:3B:CC:27:88:4B SHA1: 0B:4D:1E:83:2F:91:3A:BD:92:EB:87:62:6D:34:66:9D:6A:51:3B:ED SHA256: 91:75:AC:BE:C9:74:6F:67:3E:9A:E4:35:04:D4:05:E0:8F:A4:54:30:41:4A:EB:0A:61:E0:D1:33:7C:D8:0F:82 Signature algorithm name: SHA256withRSA Version: 3
The line that begins with SHA1 contains the certificate's SHA-1 fingerprint. The fingerprint is the sequence of 20 two-digit hexadecimal numbers separated by colons.
Creating an API Project in the Google API Console
- Go to the Google API Console.
- From the projects list, select Create a project.
- Enter a name and specify a project ID or accept the default.
- Click Create.
Setting up an Android API Key
Now you can set up an Android API key. It is possible to register more than one key per project.
To set up an Android API key
- Navigate to your project in the Google API Console.
- Go to the API Manager page, and on the left, choose Credentials.
- Click Create credentials and then select API key.
- In the Create a new key page, click Android key.
-
In the resulting dialog, click the + Add package name and fingerprint button, and then enter the appropriate information in Package name and SHA-1 certificate fingerprint.
Attention: To get a valid Android API key, ensure that you use the exact application package name. This name uniquely identifies your application. The package key in the Android Version Information contains the package name (see the screenshot under the "To set the apiKey key value" procedure later in this document).
-
Click Create.
Google API Console displays the API key window with a forty-character API key, for example:API key: AIzaSyCMuJ2w8_gQEedvqUg-9lxWXFg7feAl9PQ
Configuring Specific Project Options
For your Android application to access Google Maps, ensure that you have configured the following project options and permissions:
- Enable the appropriate uses permission.
- Enable the Maps Service entitlement option.
- Set the apiKey key value in the Android Version information.
Android
:
To check the configured permissions list
- In the RAD Studio IDE, open Project > Options > Uses Permissions
-
Ensure that you have enabled the following permissions:
- Access coarse location
- Access fine location
- Access network state
To check the Entitlement List
- In the RAD Studio IDE, open Project > Options > Entitlement List
-
Ensure that the Maps Service option is enabled:
To set the apiKey key value
- In the RAD Studio IDE, open Project > Options > Version Info
- Set the apiKey key to the Android API key value that you have requested for your application (see Step 6 in the Setting up an API Key section earlier in this document).
-
Click OK.
Shift + F9
to rebuild your project.