I am trying to implement the MyLocationOverlay class from google maps. However, when I try and use my own locationManager — I cannot get the overlay to acutally draw on the map. I am wondering if I am doing something wrong.
I don’t want to call the super method(enbaleMyLocation) of the MyLocationOverlay class because that request updates from the locationManager way too quickly and will eat my battery alive.
Here is my code:
private class CenterOverlay extends MyLocationOverlay {
private Context mContext;
private LocationManager mLocManager;
public CenterOverlay(Context context, MapView mapView) {
super(context, mapView);
this.mContext = context;
}
@Override
public void onLocationChanged(Location location) {
super.onLocationChanged(location);
try {
doExternalCenterOverlayTask(location);
} catch (JSONException e) {
e.printStackTrace();
ErrorHandler.serviceException(mContext);
} catch (IOException e) {
e.printStackTrace();
ErrorHandler.IOException(mContext);
} catch (ServiceException e) {
e.printStackTrace();
ErrorHandler.serviceException(mContext);
}
}
@Override
public boolean enableMyLocation() {
mLocManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
mLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 50, this);
mLocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 25, this);
return mLocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|| mLocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}
@Override
public void disableMyLocation() {
super.disableMyLocation();
mLocManager.removeUpdates(this);
}
@Override
public void onProviderDisabled(String provider) {
super.onProviderDisabled(provider);
ViewAdapter.createStandardAlertDialog(mContext,
"Your location provider has been disabled, please re-enable it.");
}
@Override
public void onProviderEnabled(String provider) {
super.onProviderEnabled(provider);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
super.onStatusChanged(provider, status, extras);
if (status == 0) {
ViewAdapter.showLongToast(mContext, "Location is not available at this time");
} else if (status == 1) {
//Trying to connect
} else if (status == 2) {
// Available
}
}
}
I have gotten to the bottom of this and it is not possible to do until Google feels like updating their code.
Instead, I’ve created my own class that draws the location for me — that can be updated whenever you like.
Code for that is here.
}