How to Declare Location object

Location was added in API Level 1
A data class representing a geographic location.
A location can consist of a latitude, longitude, timestamp, and other information such as bearing, altitude and velocity.
All locations generated by the LocationManager are guaranteed to have a valid latitude, longitude, and timestamp (both UTC time and elapsed real-time since boot), all other parameters are optional.

1. In the file, add the below line to the import section.

import android.location.Location;

2. Add the below line to the onCreate method. This will declare a Location object named myLocation.
Location myLocation; 

3. Compile and run!

Next Recommended Article: How to Get the Last Known Location