Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // make sure you have these permissions on in android manifest
- //<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
- // <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- // <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
- //imports
- import android.content.Context;
- import android.location.Location;
- import android.location.LocationListener;
- import android.location.LocationManager;
- String coordinates = "";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- LocationManager locationManager = (LocationManager) 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.
- System.out.println("NEW LOCATION");
- System.out.println(location.getLatitude() + "latitude" + location.getLongitude() + "longitude");
- }
- 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