Currently, my app has a mapview that creates a new MyLocationOverlay in the onCreate function.
locationOverlay = new MyLocationOverlay(this, map);
locationOverlay.runOnFirstFix(centerAroundFix);
map.getOverlays().add(locationOverlay);
I’m trying to create a button that does this optionally, much like google maps. This is what I have so far.
ImageButton locButton = (ImageButton)findViewById(R.id.googlemaps_select_location);
locButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
locationOverlay = new MyLocationOverlay(ctx, map);
locationOverlay.runOnFirstFix(centerAroundFix);
map.getOverlays().add(locationOverlay);
}
});
The only thing I had to change was the ‘this’ to ‘ctx’. I set ctx = this in the onCreate() function. I’ve also tried using getApplicationContext() instead of ctx
Using the debugger, I break on the onClick() function and can step through it. After hitting run, I telnet to the emulator and use the geo fix command to issue a fix to the emulator. Unfortunately, centerAroundFix() is never called. Not sure what I’m doing wrong, here…
I resolved this by moving
locationOverlay = new MyLocationOverlay(ctx, map)to the
onCreate()function.Perhaps
locationOverlayget garbage collected if it’s inside theonClick()function?