public class MyLocationOverlay
extends org.mapsforge.map.layer.Layer
implements android.location.LocationListener
Layer implementation to display the current location. NOTE: This code really does not reflect
Android best practice and used in production leads to bad user experience (e.g. long time to first fix, excessive
battery use, non-compliance with the Android lifecycle...). Best use the new location services provided by Google
Play Services. Also note that MyLocationOverlay needs to be added to a view before requesting location updates
(otherwise no DisplayModel is set).| Constructor and Description |
|---|
MyLocationOverlay(android.content.Context context,
org.mapsforge.map.model.MapViewPosition mapViewPosition,
org.mapsforge.core.graphics.Bitmap bitmap)
Constructs a new
MyLocationOverlay with the default circle paints. |
MyLocationOverlay(android.content.Context context,
org.mapsforge.map.model.MapViewPosition mapViewPosition,
org.mapsforge.core.graphics.Bitmap bitmap,
org.mapsforge.core.graphics.Paint circleFill,
org.mapsforge.core.graphics.Paint circleStroke)
Constructs a new
MyLocationOverlay with the given circle paints. |
| Modifier and Type | Method and Description |
|---|---|
void |
disableMyLocation()
Stops the receiving of location updates.
|
void |
draw(org.mapsforge.core.model.BoundingBox boundingBox,
byte zoomLevel,
org.mapsforge.core.graphics.Canvas canvas,
org.mapsforge.core.model.Point topLeftPoint) |
boolean |
enableMyLocation(boolean centerAtFirstFix)
Enables the receiving of location updates from the most accurate
LocationProvider available. |
android.location.Location |
getLastLocation() |
boolean |
isCenterAtNextFix() |
boolean |
isMyLocationEnabled() |
boolean |
isSnapToLocationEnabled() |
static org.mapsforge.core.model.LatLong |
locationToLatLong(android.location.Location location) |
void |
onDestroy() |
void |
onLocationChanged(android.location.Location location) |
void |
onProviderDisabled(String provider) |
void |
onProviderEnabled(String provider) |
void |
onStatusChanged(String provider,
int status,
android.os.Bundle extras) |
void |
setMinDistance(float minDistance)
Minimum distance between location updates, in meters.
|
void |
setMinTime(long minTime)
Minimum time interval between location updates, in milliseconds.
|
void |
setSnapToLocationEnabled(boolean snapToLocationEnabled) |
public MyLocationOverlay(android.content.Context context,
org.mapsforge.map.model.MapViewPosition mapViewPosition,
org.mapsforge.core.graphics.Bitmap bitmap)
MyLocationOverlay with the default circle paints.context - a reference to the application context.mapViewPosition - the MapViewPosition whose location will be updated.bitmap - a bitmap to display at the current location (might be null).public MyLocationOverlay(android.content.Context context,
org.mapsforge.map.model.MapViewPosition mapViewPosition,
org.mapsforge.core.graphics.Bitmap bitmap,
org.mapsforge.core.graphics.Paint circleFill,
org.mapsforge.core.graphics.Paint circleStroke)
MyLocationOverlay with the given circle paints.context - a reference to the application context.mapViewPosition - the MapViewPosition whose location will be updated.bitmap - a bitmap to display at the current location (might be null).circleFill - the Paint used to fill the circle that represents the accuracy of the current location (might be null).circleStroke - the Paint used to stroke the circle that represents the accuracy of the current location (might be null).public static org.mapsforge.core.model.LatLong locationToLatLong(android.location.Location location)
location - the location whose geographical coordinates should be converted.public void disableMyLocation()
public void draw(org.mapsforge.core.model.BoundingBox boundingBox,
byte zoomLevel,
org.mapsforge.core.graphics.Canvas canvas,
org.mapsforge.core.model.Point topLeftPoint)
draw in class org.mapsforge.map.layer.Layerpublic boolean enableMyLocation(boolean centerAtFirstFix)
LocationProvider available.centerAtFirstFix - whether the map should be centered to the first received location fix.public android.location.Location getLastLocation()
public boolean isCenterAtNextFix()
public boolean isMyLocationEnabled()
public boolean isSnapToLocationEnabled()
public void onDestroy()
onDestroy in class org.mapsforge.map.layer.Layerpublic void onLocationChanged(android.location.Location location)
onLocationChanged in interface android.location.LocationListenerpublic void onProviderDisabled(String provider)
onProviderDisabled in interface android.location.LocationListenerpublic void onProviderEnabled(String provider)
onProviderEnabled in interface android.location.LocationListenerpublic void onStatusChanged(String provider, int status, android.os.Bundle extras)
onStatusChanged in interface android.location.LocationListenerpublic void setMinDistance(float minDistance)
enableMyLocation(boolean).public void setMinTime(long minTime)
enableMyLocation(boolean).public void setSnapToLocationEnabled(boolean snapToLocationEnabled)
snapToLocationEnabled - whether the map should be centered at each received location fix.Copyright © 2015 mapsforge.org