Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Ben Holland
PLUS
Ben Holland
Courses Plus Student 4,062 Points

I have location ,where do i go from there ?

hey guys ,

heres my code

private void getLocation() {
        // Acquire a reference to the system Location Manager
        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.

            }

            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);
    } 

I've added the user permission in the AndroidManifest.xml for FINE_LOCATION. Imported everything i need. Now how would i incorporate this into my app ? BTW Its the Stormy app.

1 Answer

cesarruelas
cesarruelas
27,718 Points

just write that onto the MainActivity class and call it whenever you need (at start up and when you click the refresh button). You can get the latitude an longitude using getLatitude() and getLongitude() and use those instead of the ones used in the tutorial.