/**Class MyLocationListener - Used for receiving notifications from the LocationManager when the location has changed*/ public class MyLocationListener extends AsyncTask implements LocationListener{ Geocoder geoCoder = new Geocoder(getApplicationContext(), Locale.getDefault()); @Override public void onLocationChanged(Location loc){ mylat = loc.getLatitude(); mylong = loc.getLongitude(); /**A class for handling reverse geocoding. * Reverse geocoding is the process of transforming a * (latitude, longitude) coordinate into an address. */ // Geocoder geoCoder = new Geocoder(getApplicationContext(), Locale.getDefault()); try { /** Returns an array of Addresses that are known to * describe the area immediately surrounding the given * latitude and longitude. The returned addresses will * be localised for the locale provided to this class's constructor. */ List
addresses = geoCoder.getFromLocation(mylat,mylong, 1); StringBuilder sBuilder = new StringBuilder(); if(addresses.size() > 0){ Address address = addresses.get(0); for(int i=0; i < address.getMaxAddressLineIndex(); i++){ /**Returns a line of the address numbered * by the given index (starting at 0), * or null if no such line is present. */ sBuilder.append(address.getAddressLine(i)).append("\n"); // sBuilder.append(address.getLocality()).append("\n"); // sBuilder.append(address.getPostalCode()).append("\n"); }//end for addressString = sBuilder.toString(); }//end if } catch(IOException e) { addressString = "Sorry address could not be established this time\n" + e.toString(); }//end catch mycoords ="Success " + loc.getLatitude() + "," + loc.getLongitude(); final EditText latlongText = (EditText) findViewById(R.id.EditText_COord); latlongText.setEnabled(false); latlongText.setText(mycoords); }//end onLocationChanged Method @Override protected Integer doInBackground(Void... arg0) { // TODO Auto-generated method stub return null; }