Created
June 3, 2012 18:03
-
-
Save gideondsouza/2864370 to your computer and use it in GitHub Desktop.
Getting users location via network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Button btnLocation = (Button)findViewById(R.id.btnLocation); | |
btnLocation.setOnClickListener(new OnClickListener() { | |
public void onClick(View arg0) { | |
// Acquire a reference to the system Location Manager | |
LocationManager locationManager = | |
(LocationManager) AddressPOCActivity.this.getSystemService(Context.LOCATION_SERVICE); | |
// Define a listener that responds to location updates | |
LocationListener locationListener = new LocationListener() { | |
public void onLocationChanged(Location location) { | |
// Called when a new location is found by the network location provider. | |
lat = Double.toString(location.getLatitude()); | |
lon = Double.toString(location.getLongitude()); | |
TextView tv = (TextView) findViewById(R.id.txtLoc); | |
tv.setText("Your Location is:" + lat + "--" + lon); | |
} | |
public void onStatusChanged(String provider, int status, Bundle extras) {} | |
public void onProviderEnabled(String provider) {} | |
public void onProviderDisabled(String provider) {} | |
}; | |
// Register the listener with the Location Manager to receive location updates | |
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Android Studio is not detecting 'addressPOCActivity', can you help me with it?