This app displays a Google map using the Google Maps Android API version 2 in Java. The next app displays a Google map using the Google Maps JavaScript API version 3.
Tap on the red marker to display the “7 E 12” and the map toolbar (to the left of the zoom controls).
To get the project in this
.zip
file to run,
you must insert your own Google Maps Android API key
into
strings.xml
.
To get it to run on the Samsung Galaxy S5 in the Genymotion Emulator,
you must install Play Store into the S5.
MainActivity.java
.
Class
MainActivity
implements interface
OnMapReadyCallback
.
activity_main.xml
contains a
com.google.android.gms.maps.MapView
.
See
MapView
in the Google Maps Android API guides.
res/layout/info_window.xml
contains the vertical
LinearLayout
displayed by the
custom
info window.
strings.xml
.
You must insert your own Google Maps Android API key.
AndroidManifest.xml
contains six
<uses-permission>
’s
and two
<meta_data>
’s.
build.gradle
(Module: app) depends on Google Play services.
After editing this file, pull down
See this link.
In Android Studio, pull down
Tools → Android → SDK Manager
Launch Standalone SDK Manager
In the Extras folder,
make sure you have installed Google Play services and Google Repository.
Before we can run this project on the Genymotion emulator, we must install Play Store into the emulator. Its icon is a shopping bag:
I followed these instructions.
Genymotion-ARM-Translation_v1.1.zip
(9,390,250 bytes)
to the Downloads directory of your Mac.
Press the greenish “Download file” button
that eventually appears in the middle level of buttons.
You must use Chrome, not Safari, for this download,
because we need to download the
.zip
file itself.
Safari would automatically unzip the file upon arrival.
Genymotion-ARM-Translation_v1.1.zip
onto the screen of the Genymotion emulator.
When the screen becomes outlined in red, release the file.
gapps-kk-20140105-signed.zip
(87,179,530 bytes).
Press the green Begin Download file and wait eight seconds.
Then press the green “primary download” button.
gapps-kk-20140105-signed.zip
onto the screen of the Genymotion emulator.
When the screen becomes outlined in red, release the file.
.zip
files have been copied onto the emulator’s SD card:
adb devices adb -s 192.168.57.101:5555 shell ls -l /mnt/sdcard/Download -rw-rw---- root sdcard_r 9390250 2015-08-11 14:31 Genymotion-ARM-Translation_v1.1.zip -rw-rw---- root sdcard_r 87179530 2015-08-11 15:11 gapps-kk-20140105-signed.zip
Discover the
SHA-1
(Secure Hash Algorithm) fingerprint of your developer certificate.
It will be 20 colon-separated bytes, each written as a pair of hex digits.
The tilde (~
) stands for your home directory.
The
%3B
is the ASCII code of a semicolon.
See
Signing
Your Apps.
cd ~/.android pwd /Users/myname/.android ls -l debug.keystore -rw-r--r-- 1 myname mygroup 2148 Jun 17 14:20 debug.keystore file debug.keystore debug.keystore: Java KeyStore keytool -list -v -keystore debug.keystore Enter keystore password: (just press return) Certificate fingerprints: SHA1: 01:23:45:67:89:AB:CD:EF:01:23:45:67:89:AB:CD:EF:01:23:45:67
Let’s assume that your SHA-1 fingerprint is
01:23:45:67:89:AB:CD:EF:01:23:45:67:89:AB:CD:EF:01:23:45:67
and that you are creating a project whose package name is
edu.nyu.scps.mapview
Point your web browser at the following URL.
It’s suposed to be one long line.
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=01:23:45:67:89:AB:CD:EF:01:23:45:67:89:AB:CD:EF:01:23:45:67%3Bedu.nyu.scps.mapview
and follow these instructions:
Register your application for Google Maps Android API v2 in Google Developers Console
Google Developers Console allows you to manage your application and monitor API usage.
Select a project where your application will be registered
You can use one project to manage all of your applications, or you can create a different project for each application.
Create a new project
Press Continue and wait a minute.
The API is enabled
The project has been created and Google Maps Android API v2 has been enabled.
Next, to use the API you’ll need the right credentials.
Press Go to credentials.
Create Android API key
Restrict usage to your Android apps (Optional)
Android devices send API requests directly to Google.
Google verifies that each request comes from an Android app
that matches a package name and SHA1 signing-fingerprint name that you provide.
Get the package name from your AndroidManifest.xml file.
Use the following command to get the fingerprint.
Learn more
keytool -list -v -keystore mystore.keystore
Package name
edu.nyu.scps.mapview
SHA-1 certificate fingerprint
01:23:45:67:89:AB:CD:EF:01:23:45:67:89:AB:CD:EF:01:23:45:67
+ add package name and fingerprint
Create Cancel
Press Create.
API key
Here is your API key
blah blah blah
OK
Save a copy of your API key and then press OK.
When you begin to create your project, select the customary Blank Activity. (The first time I tried to use the Google Maps Android API, I selected Google Maps Activity to discover the necessary permissions and dependencies.)
To create the file
info_window.xml
,
select the folder
res/layout
in the Android Studio
project
view
and pull down
File → New → XML → Layout XML File
Layout File Name: info_window
Root Tag: LinearLayout
Finish