The Bare Bones
Far and away the simplest way to get a map into your application is to create your own subclass of . Like , which wraps up some of the smarts behind having an activity dominated by a , handles some of the nuances of setting up an activity dominated by a .
In your layout for the subclass, you need to add an element named, at the time of this writing, . This is the “longhand” way to spell out the names of widget classes, by including the full package name along with the class name. This is necessary because is not in the namespace. You can give the widget whatever attribute value you want, plus handle all the layout details to have it render properly alongside your other widgets.
However, you do need to have:
• , which in production will need to be a Google Maps API key – more on this here
• , if you want users to be able to click and pan through your map
For example, from the sample application, here is the main layout:
We’ll cover that mysterious zoom and the in later sections of this chapter. In addition, you will need a couple of extra things in your file:
• The and permissions
• Inside your , a element with , to indicate you are using one of the optional Android APIs
Here is the file for NooYawk:
That is pretty much all you need for starters, plus to subclass your activity from . If you were to do nothing else, and built that project and tossed it in the emulator, you’d get a nice map of the world. Note, however, that is abstract – you need to implement to indicate if you are supplying some sort of driving directions or not.
In theory, the user could pan around the map using the directional pad. However, that’s not terribly useful when the user has the whole world in her hands.
Since a map of the world is not much good by itself, we need to add a few things…
Дата добавления: 2015-05-16; просмотров: 762;