The Map View Control

The control can display a map. You can instantiate this control either via XML layout or code, but the activity that uses it must extend MapActivity. MapActivity takes care of multithreading requests to load a map, perform caching, and so on. Listing 4-23 shows an example instantiation of a MapView.

Listing 4-23. Creating a MapView Control via XML Layout

<LinearLayout xmlns:android="" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">

< android:layout_width="fill_parent"






As shown, the interesting thing about using the MapView is that you'll have to first obtain a mapping-API key. To get a key, you'll have to register with Google at

After you obtain an API key, you can then instantiate a MapView either programmatically or via XML. In XML, you set the android:apiKey property. In code, you'll have to pass the key to the MapView constructor. Note that we'll discuss the MapView control in detail in Chapter 7, when we discuss location-based services.

0 0

Post a comment