Advertisement
Guest User

gps android

a guest
May 26th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. // make sure you have these permissions on in android manifest
  2. //<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  3. // <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  4. // <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
  5.  
  6. //imports
  7. import android.content.Context;
  8. import android.location.Location;
  9. import android.location.LocationListener;
  10. import android.location.LocationManager;
  11.  
  12. String coordinates = "";
  13.  
  14. @Override
  15. protected void onCreate(Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  17. setContentView(R.layout.activity_main);
  18.  
  19. LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
  20.  
  21. // Define a listener that responds to location updates
  22. LocationListener locationListener = new LocationListener() {
  23. public void onLocationChanged(Location location) {
  24. // Called when a new location is found by the network location provider.
  25. System.out.println("NEW LOCATION");
  26.  
  27. System.out.println(location.getLatitude() + "latitude" + location.getLongitude() + "longitude");
  28. }
  29.  
  30. public void onStatusChanged(String provider, int status, Bundle extras) {}
  31.  
  32. public void onProviderEnabled(String provider) {}
  33.  
  34. public void onProviderDisabled(String provider) {}
  35. };
  36.  
  37. // Register the listener with the Location Manager to receive location updates
  38. locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement