|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.android.maps.Overlay com.google.android.maps.MyLocationOverlay
public class MyLocationOverlay
An Overlay
for drawing the user's current location (and
accuracy) on the map, and/or a compass-rose inset. Subclases can
override dispatchTap()
to handle taps on the current
location.
You will want to call enableMyLocation()
and/or enableCompass()
, probably from your Activity's Activity.onResume()
method, to enable the features of
this overlay. Remember to call the corresponding disableMyLocation()
and/or disableCompass()
in your Activity's
Activity.onPause()
method to turn off updates
when in the background.
Optionally, the constructor can also take a MapController
and use it to keep the "my location" dot visible by panning the map
when it would go offscreen, and a View
to View.postInvalidate()
when location or orientation is changed.
Runnables can be provided in runOnFirstFix(java.lang.Runnable)
to be run as
soon as we have a fix. (For example, this could center the map and
zoom in to show the location.)
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.google.android.maps.Overlay |
---|
Overlay.Snappable |
Field Summary |
---|
Fields inherited from class com.google.android.maps.Overlay |
---|
SHADOW_X_SKEW, SHADOW_Y_SCALE |
Constructor Summary | |
---|---|
MyLocationOverlay(android.content.Context context,
MapView mapView)
Construct a new MyLocationOverlay. |
Method Summary | |
---|---|
void |
disableCompass()
Disable updates from the compass sensor. |
void |
disableMyLocation()
Stops location updates. |
protected boolean |
dispatchTap()
Handle a tap on the "my location" point. |
boolean |
draw(android.graphics.Canvas canvas,
MapView mapView,
boolean shadow,
long when)
Draw method. |
protected void |
drawCompass(android.graphics.Canvas canvas,
float bearing)
Draw the compass inset. |
protected void |
drawMyLocation(android.graphics.Canvas canvas,
MapView mapView,
android.location.Location lastFix,
GeoPoint myLocation,
long when)
Draw the "my location" dot. |
boolean |
enableCompass()
Enable updates from the compass sensor. |
boolean |
enableMyLocation()
Attempts to enable MyLocation, registering for updates from LocationManager.GPS_PROVIDER and LocationManager.NETWORK_PROVIDER . |
android.location.Location |
getLastFix()
Returns a Location corresponding to the most-recently-set user location. |
GeoPoint |
getMyLocation()
Returns a GeoPoint corresponding to the most-recently-set user location. |
float |
getOrientation()
Returns the most-recently-set compass bearing. |
boolean |
isCompassEnabled()
Checks whether the compass widget is displayed. |
boolean |
isMyLocationEnabled()
Checks whether location awareness is enabled (via GPS or network). |
void |
onAccuracyChanged(int sensor,
int accuracy)
|
void |
onLocationChanged(android.location.Location location)
Listener to get location updates from LocationManagerService. |
void |
onProviderDisabled(java.lang.String provider)
|
void |
onProviderEnabled(java.lang.String provider)
|
void |
onSensorChanged(int sensor,
float[] values)
Called by the SensorManager when the compass value changes. |
boolean |
onSnapToItem(int x,
int y,
android.graphics.Point snapPoint,
MapView mapView)
Checks to see if the given x and y are close enough to an item resulting in snapping the current action (e.g. |
void |
onStatusChanged(java.lang.String provider,
int status,
android.os.Bundle extras)
|
boolean |
onTap(GeoPoint p,
MapView map)
Checks whether the location of the tap is close enough to the current location (if it's known). |
boolean |
runOnFirstFix(java.lang.Runnable runnable)
Queues a runnable to be executed as soon as we have a location fix. |
Methods inherited from class com.google.android.maps.Overlay |
---|
draw, drawAt, onKeyDown, onKeyUp, onTouchEvent, onTrackballEvent |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MyLocationOverlay(android.content.Context context, MapView mapView)
context
- A context to be used for accessing system services.mapView
- The MapView on which the location is to be overlayed.
java.lang.IllegalArgumentException
- if mapView is null.Method Detail |
---|
public boolean enableCompass()
public void disableCompass()
public boolean isCompassEnabled()
public boolean enableMyLocation()
LocationManager.GPS_PROVIDER
and LocationManager.NETWORK_PROVIDER
.
public void disableMyLocation()
It is safe to call this method even if location updates are currently disabled.
public void onSensorChanged(int sensor, float[] values)
onSensorChanged
in interface android.hardware.SensorListener
public void onLocationChanged(android.location.Location location)
onLocationChanged
in interface android.location.LocationListener
public void onStatusChanged(java.lang.String provider, int status, android.os.Bundle extras)
onStatusChanged
in interface android.location.LocationListener
public void onProviderEnabled(java.lang.String provider)
onProviderEnabled
in interface android.location.LocationListener
public void onProviderDisabled(java.lang.String provider)
onProviderDisabled
in interface android.location.LocationListener
public boolean onSnapToItem(int x, int y, android.graphics.Point snapPoint, MapView mapView)
Overlay.Snappable
onSnapToItem
in interface Overlay.Snappable
x
- The x in screen coordinates.y
- The y in screen coordinates.snapPoint
- To be filled with the the interesting point (in
screen coordinates) that is closest to the given x and y. Can
be untouched if not snapping.mapView
- The MapView that is requesting the snap. Use
MapView.getProjection()
to convert between on-screen
pixels and latitude/longitude pairs.
public boolean onTap(GeoPoint p, MapView map)
dispatchTap()
; otherwise returns false.
Handle a "tap" event. This can be either a touchscreen tap
anywhere on the map, or a trackball click on the center of the
map. By default does nothing and returns false.
onTap
in class Overlay
p
- The point that has been tapped.map
- the MapView that generated the tap event
protected boolean dispatchTap()
public boolean draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow, long when)
drawMyLocation(android.graphics.Canvas, com.google.android.maps.MapView, android.location.Location, com.google.android.maps.GeoPoint, long)
if we
have a location fix, and then to drawCompass(android.graphics.Canvas, float)
if we
have a compass reading. We return false since we don't require
an immediate redraw; however, a delayed invalidate may be posted
on the viewToInvalidate passed to this class's constructor in
order to trigger the next phase in the animation of the blue location
dot.
draw
in class Overlay
canvas
- The Canvas upon which to draw. Note that this
may already have a transformation applied, so be sure to leave
it the way you found it.mapView
- the MapView that requested the draw. Use MapView.getProjection()
to convert between on-screen pixels and
latitude/longitude pairs.shadow
- If true, draw the shadow layer. If false, draw the
overlay contents.when
- The timestamp of the draw.
protected void drawMyLocation(android.graphics.Canvas canvas, MapView mapView, android.location.Location lastFix, GeoPoint myLocation, long when)
MapController
in our constructor, we'll scroll
to recenter the new reading.
canvas
- the Canvas to draw to.mapView
- the mapView calling the draw.lastFix
- the last location fix we received.myLocation
- the coordinates of the last fix, extracted
into handy GeoPoint
form.when
- the drawing time, in millisecondsprotected void drawCompass(android.graphics.Canvas canvas, float bearing)
canvas
- The Canvas to draw to.bearing
- The estimated bearing of the phone, in degrees east of north.public GeoPoint getMyLocation()
public android.location.Location getLastFix()
public float getOrientation()
public boolean isMyLocationEnabled()
public boolean runOnFirstFix(java.lang.Runnable runnable)
public void onAccuracyChanged(int sensor, int accuracy)
onAccuracyChanged
in interface android.hardware.SensorListener
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |