Advertisement
Guest User

Untitled

a guest
Mar 9th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.77 KB | None | 0 0
  1. /**Class MyLocationListener - Used for receiving notifications
  2.             from the LocationManager when the location has changed*/
  3.             public class MyLocationListener extends AsyncTask<Void, Void, Integer> implements LocationListener{
  4.                 Geocoder geoCoder = new Geocoder(getApplicationContext(), Locale.getDefault());
  5.                 @Override
  6.                 public void onLocationChanged(Location loc){
  7.                              mylat = loc.getLatitude();
  8.                              mylong = loc.getLongitude();
  9.                              
  10.                
  11.                  /**A class for handling reverse geocoding.  
  12.                   * Reverse geocoding is the process of transforming a
  13.                   * (latitude, longitude) coordinate into an address. */
  14.                 // Geocoder geoCoder = new Geocoder(getApplicationContext(), Locale.getDefault());
  15.                                  
  16.                     try {
  17.                           /** Returns an array of Addresses that are known to
  18.                            *  describe the area immediately surrounding the given
  19.                            *   latitude and longitude. The returned addresses will
  20.                            *    be localised for the locale provided to this class's constructor. */
  21.                             List<Address> addresses = geoCoder.getFromLocation(mylat,mylong, 1);
  22.                    
  23.                               StringBuilder sBuilder = new StringBuilder();
  24.                               if(addresses.size() > 0){
  25.                                       Address address = addresses.get(0);
  26.                                       for(int i=0; i <  address.getMaxAddressLineIndex(); i++){
  27.                    
  28.                         /**Returns a line of the address numbered
  29.                          *  by the given index (starting at 0),
  30.                          *   or null if no such line is present. */
  31.                                  
  32.                      sBuilder.append(address.getAddressLine(i)).append("\n");                                      
  33.                     //  sBuilder.append(address.getLocality()).append("\n");                                  
  34.                     //  sBuilder.append(address.getPostalCode()).append("\n");
  35.                                                          
  36.                                            }//end for
  37.                                          
  38.                                       addressString = sBuilder.toString();
  39.                                   }//end if
  40.                           } catch(IOException e) {
  41.                                   addressString = "Sorry address could not be established this time\n" +
  42.          
  43.                                   e.toString();
  44.                           }//end catch
  45.  
  46.                           mycoords ="Success " + loc.getLatitude() + "," + loc.getLongitude();
  47.                                                
  48.                         final EditText latlongText = (EditText) findViewById(R.id.EditText_COord);
  49.                        latlongText.setEnabled(false);
  50.                        
  51.                             latlongText.setText(mycoords);
  52.                    
  53.                 }//end onLocationChanged Method
  54.                    
  55.                 @Override
  56.                 protected Integer doInBackground(Void... arg0) {
  57.                     // TODO Auto-generated method stub
  58.                     return null;
  59.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement