My code currently displays the users location on a map… using the code below
private void initMyLocation() {
final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
overlay.enableMyLocation();
overlay.runOnFirstFix(new Runnable() {
public void run() {
controller.setZoom(8);
controller.animateTo(overlay.getMyLocation());
}
});
map.getOverlays().add(overlay);
}
I want to use the current location of the user and perform geocding on it to display the address as a toast message.. Would i have to delete the code above and retrieve the location by separate longitude and latitude values? Preferably i wouldnt want to go changing the code above as it already works.. I can’t seem to find any good tutorials out there.. Could someone please direct me to one?
Thanks
Since
MyLocationOverlayalready implementsLocationListener, you could simply subclass it and override theonLocationChangedlistener method and perform your geocoding there (preferably in a new thread/async task to avoid blocking the overlay processing!).Something like:
The other option might be to write a custom
LocationListenerand register for updates for location and do pretty much the same thing as in the code above. IMO, this is probably redundant and unnecessarily expensive since, as explained above, you already have aLocationListenerimplementation to hook into so why write another?