Integrating Google maps into an Android application
Posted By : Sapna Sharma | 28-Dec-2014
An Android application that uses the Google Maps Android API v2 requires several steps. The overall process can be described as following :
Install Google Play Services SDK
The Google Maps v2 module uses Google Maps Android API v2, which requires the Google Play Services SDK. To install the Google Play Services follow the below given steps.
1. Launch Android SDK manager. To launch the Android SDK manager type following command in your terminal:
android ( #If the Android SDK tools folder is in your path ) otherwise
<path_to_android_sdk>/tools/android
2. After the Android SDK Manager application launches, in the Extras folder, select Google Play services, then click Install X Packages....
3. A dialog appears confirming your selection. Accept the license and click Install to continue.
Obtain and Add Google API Key
1 . Create an API project in the Google APIs Console
a. In a browser, navigate to the 'Google APIs Console' .
- If you did not use the Google APIs Console before, you need to create a project . Click Create Project; A new project will be created called API Project. On the next page, this name appears in the upper left hand corner. To rename or otherwise manage the project, you need to click on its name.
- If you have used the Google APIs Console already, you will immediately see a list of your existing projects and the available services. But still if you create a new project for Google Maps Android API then its a good idea.
b. Now you need to select Google Maps Android API Service . See the list of APIs and services in the main window.
c. In the list displayed , select Google Maps Android API v2 .To select it, click switch indicator so that it gets on .
d. This will display the Google Maps Android API Terms of Service. If you agree to the terms of service , This will return you to the list of APIs and services .
2. Obtain and add Google Maps API key to your project
Obtain Google Maps API key - To obtain Google Maps API key, two things will be needed - a package name and a SHA-1 certificate fingerprint.
- The package name is the Application ID from the tiapp.xml file.
- If you are using the Run command from Studio to build and test your application for an Android Device, use the debug certificate. If you are using the Publish command from Studio to package and distribute your application to the Android App Store, use the release certificate.
Obtain the SHA-1 certificate fingerprint - For the debug certificate, the SHA-1 certificate fingerprint is stored in a keystore file that comes with each Titanium SDK. To obtain SHA-1 certificate fingerprint from keystore run following command :
keytool -list -v -keystore ~/Library/Application\ Support/Titanium/mobilesdk/<platform>/<sdk_version>/android/dev_keystore
If password is required you simply need to hit enter (no password). Use the SHA1 string under Certificate fingerprints.
For the release certificate, follow the directions from Distributing Android apps to create your release certificate, then run the keytool command to retrieve the SHA-1 certificate fingerprint.
generate Google Maps API key
If your application is registered with the Google Maps Android API v2 service, then you can request an API key. It's possible to register more than one key per project.
a. Navigate to your project in the Google APIs Console.
b. In the Services page, verify that the "Google Maps Android API v2" is enabled.
c. In the left navigation bar, click API Access.
d. In the resulting page, click Create New Android Key....
e. In the resulting dialog, enter the SHA-1 fingerprint, then a semicolon, then your application's package name.
f. The Google APIs Console responds by displaying Key for Android apps (with certificates) followed by a forty-character API key.
Add Google API key and permissions to the tiapp.xml file
After obtainning Google API key,you need to add it as well as permissions in your tiapp.xml file. Add all permissions(shown below ) to the android section of tiapp.xml file . Also the replace <com.domain.appid> with your application's ID i,e. package name and replace "PASTE YOUR GOOGLE MAPS API KEY HERE" with your Google API key .
Add Module to Your Project
The ti.map module is required for the whole process of including map in your app . You do not need to download this module since it is included as part of the Titanium SDK . You simply need to edit your tiapp.xml file to use it.
In studio inside tiapp.xml select the GUI Overview tab in TiApp Editor, and in the Modules section, click the add button (green plus sign), select the ti.map module, finally click the OK button .
or you can add the following modules section code to your tiapp.xml file:
ti.map
With the help of above steps the module will be added to your project. Now to use this module within your application's JavaScript files, instantiate the module with the require('ti.map') method as shown below
var MapModule = require('ti.map');
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Sapna Sharma
Sapna is a bright Android Apps developer using Titanium framework. Sapna likes music and helping needy people.