Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement