0

I want to be able to do this:

I have a TextView and a Button. When I click on the Button, the text of the TextView should be set to the name of my current locality.

I found some examples that use the LocationManager and LocationListener but it seems the LocationListener listens for onLocationChanged.

Any ideas on how to achieve what I want to do?

Nii Laryea
  • 1,211
  • 5
  • 18
  • 31
  • have u checked in your device that GPS location is on or not – satya prakash May 03 '14 at 12:26
  • onLocationChanged will work, since it will get your first location which you can store as a variable. If you move it will update, if not there is no need to update as you already have your stored location. – zgc7009 May 03 '14 at 12:29

2 Answers2

0

Please use the google map api to get the current location and then print the address of that location from the given lat long. i know its not detail answer but sure that it will be provide you the hint to start the solve the problem.

0

try this it's the best way to do this........

LocationManager mLocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); LocationListener mLocListener = new MyLocationListener(); mLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocListener);

public class MyLocationListener implements LocationListener{

    public void onLocationChanged(Location loc) {           
        String message = String.format(
                    "New Location \n Longitude: %1$s \n Latitude: %2$s",
                    location.getLongitude(), location.getLatitude()
            );
            Toast.makeText(LbsGeocodingActivity.this, message, Toast.LENGTH_LONG).show();
    }
    public void onProviderDisabled(String arg0) {

    }
    public void onProviderEnabled(String provider) {

    }
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }       
}
satya prakash
  • 238
  • 3
  • 13
  • `onLocationChanged` doesn't seem to get executed, so I do not receive any location updates. And I have tried exactly as you have up there. – Nii Laryea May 03 '14 at 18:12
  • I tried this solution too which yours is almost like http://stackoverflow.com/a/10917500/1319753. Same issue: `onLocationChanged` doesn't seem to get executed ever. What am I not doing? – Nii Laryea May 05 '14 at 16:28