The Map View and Map Activity

Write App Reviews

Build your own Android App Dev Empire

Get Instant Access

This book's MJAndroid application needs to be able to add overlays that show the locations for jobs in the area. So instead of using the Google Maps application, we will use a MapView, which we can overlay with as many graphics as we want. You can have only one MapView per Activity, however, and your activity has to extend MapActivity. As you'll see, that's a small price to pay for all the functionality that comes for free.

There are a couple of unique prerequisites for using MapViews in your application, and we touched on both of them when we looked at the initialization of MJAndroid in Chapter 4.

Include the MapViews library

The MapView is not included in the default Android libraries, so you need to specify in AndroidManifest.xml that we are using this additional library:

<application android:icon="@drawable/icon2">

<uses-library android:name="" />

You can't put the uses-library line just anywhere in AndroidManifest.xml; it needs to be within the <application> tag and outside of the <activity> tag definitions.

Sign your application and obtain a Map apiKey from Google

When you use a MapView in your application, you are using actual Google Maps data to draw the map. For legal reasons, Google needs to track who is using their map data. They don't care what your application does with it, but they need to have you register with them for an API key and agree to appropriate Terms of Service. This tells them your application is using mapping data, and whether you are also using the routing data that is available from Google Maps. Chapter 7 covered the processes of signing your application and getting an apiKey.

Remember that programs using a MapView must be signed. To make it easy for you to try out the MJAndroid example from this book, we've included an .apk file as described in the sidebar "Running the MJAndroid Code" on page 35 in Chapter 3. If you change the code or do any coding of your own, you need to get your own key, as described in Chapter 7.

Was this article helpful?

0 0


  • wolfgang
    Can t extend mapactivity?
    8 years ago

Post a comment