Class MapView

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).

Source code in MapView.zip

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.

  1. MainActivity.java. Class MainActivity implements interface OnMapReadyCallback.
  2. activity_main.xml contains a com.google.android.gms.maps.MapView. See MapView in the Google Maps Android API guides.
  3. res/layout/info_window.xml contains the vertical LinearLayout displayed by the custom info window.
  4. strings.xml. You must insert your own Google Maps Android API key.
  5. AndroidManifest.xml contains six <uses-permission>’s and two <meta_data>’s.
  6. build.gradle (Module: app) depends on Google Play services. After editing this file, pull down
    Tools → Android → Sync Project with Gradle Files.

Install Google Play on Amazon Fire

See this link.

Install Google Play services and Google Repository into Android Studio

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.

Install Play Store into the Samsung Galaxy S5 in Genymotion

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.

  1. Go here to download the file 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.

  2. Drag Genymotion-ARM-Translation_v1.1.zip onto the screen of the Genymotion emulator. When the screen becomes outlined in red, release the file.

    File transfer in progress…
    File Genymotion-ARM-Translation_v1.1.zip seems to be a flashable archive. Do you want to flash it to the virtual device?
    Caution: this operation may corrupt the virtual device.
    Press OK.
    File transfer in progress…
    File Genymotion-ARM-Translation_v1.1.zip has been flashed successfully. Please restart the virtual device.
    Press OK.

  3. To restart the virtual device, pull down
    player → Quit player
    Then launch the emulator again.

  4. Go here to download 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.

  5. Drag gapps-kk-20140105-signed.zip onto the screen of the Genymotion emulator. When the screen becomes outlined in red, release the file.

    File transfer in progress…
    File gapps-kk-20140105-signed.zip seems to be a flashable archive. Do you want to flash it to the virtual device?
    Caution: this operation may corrupt the virtual device.
    Press OK.
    File transfer in progress…
    File gapps-kk-20140105-signed.zip has been flashed successfully. Please restart the virtual device.
    Press OK.

  6. To restart the virtual device, pull down
    player → Quit player
    Then launch the emulator again. For your information, the two .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
    

  7. You may get many dialog boxes that say “Unfortunately, Google Play services has stopped.” You will just have to keep pressing the OK button to swat them away.

  8. Click on the Play Store icon.
    Add a Google Account.
    Do you want to add an existing account or create a new one?
    Press Existing.
    Sign in.
    Email:
    Password:
    Done
    By signing in, you are agreeing to the Google Terms of Service, Privacy Policy, and Google Play Terms of Service.
    Press OK.
    Signing In…
    This can take a few minutes.
    Google services
    Press the isoceles right triangle in the lower right corner.
    Click on the shopping bag icon at the left end of the action bar. Select “My apps”. The INSTALLED tab at the top of the screen should already be selected. The circles will go round and round for a long time; you don’t have to wait until they finish. The “Unfortunately, Google Play services has stopped” dialog boxes should start to taper off at this point.

Find your SHA-1 fingerprint

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

Get a Google Maps API key

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.

Create the project

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

Things to try

  1. How can we display the dropdown menu displayed in Map?