Android demo using the Google Geocoding, Elevation and Civic Information APIs: the project builds a simple Android application that gives geocoding and elevation data, plus a complete list of elected officials (in the US at least), for a given address string. The application will run fine on a connected device or AVD emulator (use an Android-21 system image). The same source code project can be used to build Maven and ant (Eclipse ADT) builds.
You will need a Google API key to access the Geocoding API, Elevation API and Google Civic Information API: these services have courtesy limits, which allow limited use free of charge. Use the Google API Console to create a Google API project, add the required services (APIs & Auth -> API) and then create an API Key (APIs & Auth -> Credentials). Create a Browser key and leaved the Allowed Referers field blank.
Create the following class file (GooglePlacesKey.java
) in src/com/example/appdynamics/placesdemo
and paste in your API key:
package com.example.appdynamics.placesdemo;
public class GooglePlacesKey {
public static final String API_KEY = "<your API key>";
}
- Import -> Existing Android code into workspace
- Properties -> Android -> Android 5.0 (API Level 21)
- Build Path -> Configure Build Path -> Libraries -> Add External JARs
- Clean and rebuild the project
The following JAR files need to be added to the project:
- google-api-client-1.19.0.jar
- google-api-services-civicinfo-v2-rev7-1.19.0.jar
- google-http-client-1.19.0.jar
- google-http-client-android-1.19.0.jar
- google-http-client-gson-1.19.0.jar
- gson-2.3.jar
- To build:
mvn clean install
- To deploy to a connected device or emulator:
mvn android:deploy
- To run:
mvn android:run
To build with different Android platform versions, download the maven-android-sdk-deployer tool and follow the instructions in the README file. For example, to install Maven libraries for Android-21, run mvn install -P 5.0
and use the following dependency:
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>5.0_r1</version>
<scope>provided</scope>
</dependency>