Книга: Beginning Android
My, Myself, and MyLocationOverlay
My, Myself, and MyLocationOverlay
Android has a built-in overlay to handle two common scenarios:
• Showing where you are on the map, based on GPS or other location-providing logic
• Showing where you are pointed, based on the built-in compass sensor, where available
All you need to do is create a MyLocationOverlay
instance, add it to your MapView
’s list of overlays, and enable and disable the desired features at appropriate times.
The “at appropriate times” notion is for maximizing battery life. There is no sense in updating locations or directions when the activity is paused, so it is recommended that you enable these features in onResume()
and disable them in onPause()
.
For example, NooYawk
will display a compass rose using MyLocationOverlay
. To do this, we first need to create the overlay and add it to the list of overlays:
me = new MyLocationOverlay(this, map);
map.getOverlays().add(me);
Then, we enable and disable the compass rose as appropriate:
@Override
public void onResume() {
super.onResume();
me.enableCompass();
}
@Override
public void onPause() {
super.onPause();
me.disableCompass();
}
- CHAPTER 34 Mapping with MapView and MapActivity
- Разработка приложений баз данных InterBase на Borland Delphi
- Open Source Insight and Discussion
- Introduction to Microprocessors and Microcontrollers
- Chapter 6. Traversing of tables and chains
- Chapter 8. Saving and restoring large rule-sets
- Chapter 11. Iptables targets and jumps
- Chapter 5 Installing and Configuring VirtualCenter 2.0
- Chapter 16. Commercial products based on Linux, iptables and netfilter
- Appendix A. Detailed explanations of special commands
- Appendix B. Common problems and questions
- Appendix E. Other resources and links