views:

600

answers:

1

i am creating a Geocoder object like.

Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());

here i got this error in eclipse. i.e.

The method getBaseContext() is undefined for the type MyMapOverlay

getBaseContext() is a default method in android.content.ContextWrapper class.

what is the problem here.. any idea???

A: 

The question is: In which class do you create a Geocoder object? The getBaseContext() does not work in a class which extends from Overlay, because Overlay is not a child of ContextWrapper.
It exists in your MapActivity, if you use one. The easiest way to solve the issue is to give the Overlay the context as parameter/setter method.

WarrenFaith
see this example for Geocoder: http://mobiforge.com/developing/story/using-google-maps-android . they uses the getBaseContext inside the class which extends Overlay. why?
Praveen Chandrasekaran
Because in this example, the MyMapOverlay class is a inner class of the activity and therefor can access everything the MapActivity provide.<br/>If you create a normal class for your Overlay, you have to hand over the context by yourself.
WarrenFaith
got it.thanks a lot.
Praveen Chandrasekaran