---
# System prepended metadata

title: Unit 7 Lab - Using Google Maps API

---

# Unit 7 Lab - Using Google Maps API

### Challenge

This week we will be learning how to add Google Maps to your application.  You'll be able to render a Google Map view, add icons to the app, and add alert dialogs and windows to a Google Maps view.

If you are using the default x86-based emulator instead, make sure your virtual device comes with Google APIs and Google Play support as mentioned in [this guide](http://guides.codepath.org/android/Google-Maps-Fragment-Guide#setup-x86-based-emulator).  The most complicated part of this assignment will be setting up Google Maps on your phone.

<img src="http://i.imgur.com/1rh8jLa.jpg" height="500"/>

#### Steps

1. Obtain a Google Maps API key
   * Follow [register for an API key](http://guides.codepath.org/android/Google-Maps-Fragment-Guide#get-api-key) guide.

2. Import Maps Demo
   * Make sure your emulator or is setup properly before attempting this step.
   * Refer [import maps demo](http://guides.codepath.org/android/Google-Maps-Fragment-Guide#import-maps-demo) guide and follow the steps to verify that google maps is showing up on your device or emulator.
   * To change locations, you will need to make sure to [send the coordinates](http://guides.codepath.org/android/Google-Maps-Fragment-Guide#official-emulator).
   * **Troubleshooting:** If you encounter compilation errors, select `File --> Invalidate Caches/Restart` from Android Studio

3. Test your app
   * Test to verify that maps is loading correctly on your screen.
   * Follow the [troubleshooting guide](http://guides.codepath.org/android/Google-Maps-Fragment-Guide#troubleshooting) if maps fails to load on your device.

4. Show AlertDialog and Add Marker
   * After you have successfully loaded the map, bring up an AlertDialog for the user to type in a message on LongClick event. On completion, have a marker added that when clicked displays the message in an info window.
   * Refer [show AlertDialog on long click](http://guides.codepath.org/android/Google-Maps-API-v2-Usage#show-alertdialog-on-longclick) guide.

5. Swap the marker pin for a [speech bubble](http://guides.codepath.org/android/Google-Maps-API-v2-Usage#speech-bubbles).

6. Set your map and markers to be draggable.
   * Refer [enable markers to be draggable guide](http://guides.codepath.org/android/Google-Maps-API-v2-Usage#enable-markers-to-be-draggable).

7. Run and test your app.
