Книга: 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();
}

Оглавление книги


Генерация: 2.364. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз