com.google.android.maps
Class MapController

java.lang.Object
  extended by com.google.android.maps.MapController
All Implemented Interfaces:
android.view.View.OnKeyListener

public final class MapController
extends java.lang.Object
implements android.view.View.OnKeyListener

A utility class to manage panning and zooming of a map.


Method Summary
 void animateTo(GeoPoint point)
          Start animating the map towards the given point.
 void animateTo(GeoPoint point, android.os.Message message)
          Start animating the map towards the given point.
 void animateTo(GeoPoint point, java.lang.Runnable runnable)
          Start animating the map towards the given point.
 boolean onKey(android.view.View v, int keyCode, android.view.KeyEvent event)
          Processes key events and translates them into appropriate panning of the map.
 void scrollBy(int x, int y)
          Scroll by a given amount, in pixels.
 void setCenter(GeoPoint point)
          Set the map view to the given center.
 int setZoom(int zoomLevel)
          Sets the zoomlevel of the map.
 void stopAnimation(boolean jumpToFinish)
          Stops any animation that may be in progress, and conditionally update the map center to whatever offset the partial animation had achieved.
 void stopPanning()
          Resets the pan state to make the map stationary.
 boolean zoomIn()
          Zoom in by one zoom level.
 boolean zoomInFixing(int xPixel, int yPixel)
          Zoom in by one zoom level.
 boolean zoomOut()
          Zoom out by one zoom level.
 boolean zoomOutFixing(int xPixel, int yPixel)
          Zoom out by one zoom level.
 void zoomToSpan(int latSpanE6, int lonSpanE6)
          Attempts to adjust the zoom of the map so that the given span of latitude and longitude will be displayed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

stopPanning

public void stopPanning()
Resets the pan state to make the map stationary. This could be necessary if we receive a key-down event but will never receive the corresponding key-up.


onKey

public boolean onKey(android.view.View v,
                     int keyCode,
                     android.view.KeyEvent event)
Processes key events and translates them into appropriate panning of the map. Defined in View.OnKeyListener.

Specified by:
onKey in interface android.view.View.OnKeyListener

animateTo

public void animateTo(GeoPoint point)
Start animating the map towards the given point.


animateTo

public void animateTo(GeoPoint point,
                      android.os.Message message)
Start animating the map towards the given point. If and when the animation reaches its natural conclusion, dispatch the given message (if non-null). The message will not be dispatched if the animation is aborted.


animateTo

public void animateTo(GeoPoint point,
                      java.lang.Runnable runnable)
Start animating the map towards the given point.

Parameters:
point - Where to animate the map towards.
runnable - If and when the animation reaches its natural conclusion, this callback will be run on the UI thread. The callback will not be run if the animation is aborted.

scrollBy

public void scrollBy(int x,
                     int y)
Scroll by a given amount, in pixels. There will be no animation.

Parameters:
x - the horizontal scroll amount in pixels.
y - the vertical scroll amount in pixels.

setCenter

public void setCenter(GeoPoint point)
Set the map view to the given center. There will be no animation.


stopAnimation

public void stopAnimation(boolean jumpToFinish)
Stops any animation that may be in progress, and conditionally update the map center to whatever offset the partial animation had achieved.

Parameters:
jumpToFinish - if true, we'll shortcut the animation to its endpoint. if false, we'll cut it off where it stands.

setZoom

public int setZoom(int zoomLevel)
Sets the zoomlevel of the map. The value will be clamped to be between 1 and 21 inclusive, though not all areas have tiles at higher zoom levels. This just sets the level of the zoom directly; for a step-by-step zoom with fancy interstitial animations, use zoomIn() or zoomOut().

Parameters:
zoomLevel - At zoomLevel 1, the equator of the earth is 256 pixels long. Each successive zoom level is magnified by a factor of 2.
Returns:
the new zoom level, between 1 and 21 inclusive.

zoomToSpan

public void zoomToSpan(int latSpanE6,
                       int lonSpanE6)
Attempts to adjust the zoom of the map so that the given span of latitude and longitude will be displayed. Because the zoom can only achieve discrete levels, and because the aspect ratio of the map may not match the ratio given, the quality of the fit may vary. The only thing we guarantee is that, after the zoom, at least one of the new latitude or the new longitude will be within a factor of 2 from the corresponding parameter.


zoomIn

public boolean zoomIn()
Zoom in by one zoom level. This begins an animated zoom step. If you have added the ZoomControls View (from MapView.getZoomControls()), then this will also call through to MapView.displayZoomControls(boolean) causing the ZoomControls to appear briefly, but they will not take focus.

Returns:
true if we managed to zoom in, false if we hit the limit.

zoomOut

public boolean zoomOut()
Zoom out by one zoom level. This begins an animated zoom step. If you have added the ZoomControls View (from MapView.getZoomControls()), then this will also call through to MapView.displayZoomControls(boolean) causing the ZoomControls to appear briefly, but they will not take focus.

Returns:
true if we managed to zoom out, false if we hit the limit.

zoomInFixing

public boolean zoomInFixing(int xPixel,
                            int yPixel)
Zoom in by one zoom level. This begins an animated zoom step. If you have added the ZoomControls View (from MapView.getZoomControls()), then this will also call through to MapView.displayZoomControls(boolean) causing the ZoomControls to appear briefly, but they will not take focus.

This zoom will also pan the map to keep a single point fixed on the screen. Specify the point you want fixed by giving its pixel coordinates.

Parameters:
xPixel - offset, in pixels from the left of the map, where the fixed point of our zoom will be.
yPixel - offset, in pixels from the top of the map, where the fixed point of our zoom will be.
Returns:
true if we managed to zoom in, false if we hit the limit.

zoomOutFixing

public boolean zoomOutFixing(int xPixel,
                             int yPixel)
Zoom out by one zoom level. This begins an animated zoom step. If you have added the ZoomControls View (from MapView.getZoomControls()), then this will also call through to MapView.displayZoomControls(boolean) causing the ZoomControls to appear briefly, but they will not take focus.

This zoom will also pan the map to keep a single point fixed on the screen. Specify the point you want fixed by giving its pixel coordinates.

Parameters:
xPixel - offset, in pixels from the left of the map, where the fixed point of our zoom will be.
yPixel - offset, in pixels from the top of the map, where the fixed point of our zoom will be.
Returns:
true if we managed to zoom out, false if we hit the limit.