I've got an application that is supposed to find address name from latitude and longitude from a pressing a button. I've been using reverse geocoding and it's worked until a couple of days ago when I tried to add another button. Since then everytime I debug the code it skips the address line and exits the method. I can't figure out what's wrong as the code was working fine before.
This is the code I've been using
public class MainActivity extends Activity implements LocationListener{
protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
//declaration of variables for latitude and longitude
TextView txtLat;
TextView txtLon;
String lat;
String provider;
protected String latitude,longitude;
protected boolean gps_enabled, network_enabled;
private static final long time_bw_up_min = 50*60;
double latitudedouble;
double longitudedouble;
List<AddressList> addressList;
private static final long dist_change_update_min = 10;
public MainActivity() {
this.addressList = null;
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//initialize the text displays showing latitude and longitude
txtLat = (TextView) findViewById(R.id.latitude);
txtLon = (TextView) findViewById(R.id.longitude);
//run the method to access the devices location
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,time_bw_up_min,dist_change_update_min, this);
}
public void goButtonClicked(View v) {
Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);
String result = null;
try {
List<Address> list = geocoder.getFromLocation(latitudedouble, longitudedouble, 1);
if (list != null && list.size()>0) {
Address address = list.get(0);
result = address.getAddressLine(0) + ", " + address.getLocality();
txtLat.setText(result);
}
} catch (IOException ex) {
Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void onLocationChanged(Location location) {
//find the text view for latitude
txtLat = (TextView) findViewById(R.id.latitude);
//change the text from the text view to the latitude of the device
txtLat.setText("Latitude: " + location.getLatitude());
//declare a variable to save the device's latitude
latitudedouble = location.getLatitude();
//find the text view for longitude
txtLon = (TextView) findViewById(R.id.longitude);
//change the text from the text view to the longitude of the device
txtLon.setText("Longitude: " + location.getLongitude());
//declare a variable to save the device's longitude
longitudedouble = location.getLongitude();
}
@Override
public void onProviderDisabled(String provider) {
Log.d("Latitude","disable");
}
@Override
public void onProviderEnabled(String provider) {
Log.d("Latitude","enable");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("Latitude","status");
}
}
}
The other methods work fine. It's just the code under the goButtonClicked
method that hasn't been executing