Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. Button btnLocation = (Button)findViewById(R.id.btnLocation);
  2. btnLocation.setOnClickListener(new OnClickListener() {
  3. public void onClick(View arg0) {
  4. // Acquire a reference to the system Location Manager
  5. LocationManager locationManager =
  6. (LocationManager) AddressPOCActivity.this.getSystemService(Context.LOCATION_SERVICE);
  7. // Define a listener that responds to location updates
  8. LocationListener locationListener = new LocationListener() {
  9. public void onLocationChanged(Location location) {
  10. // Called when a new location is found by the network location provider.
  11. lat = Double.toString(location.getLatitude());
  12. lon = Double.toString(location.getLongitude());
  13. TextView tv = (TextView) findViewById(R.id.txtLoc);
  14. tv.setText("Your Location is:" + lat + "--" + lon);
  15. }
  16.  
  17. public void onStatusChanged(String provider, int status, Bundle extras) {}
  18. public void onProviderEnabled(String provider) {}
  19. public void onProviderDisabled(String provider) {}
  20. };
  21. // Register the listener with the Location Manager to receive location updates
  22. locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
  23. }
  24. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement