Overview
TheDeviceLocation data class represents a geographic location with latitude and longitude coordinates. It’s used throughout the EV Sum 2 application to represent device position.
Class Definition
Properties
The latitude coordinate in decimal degreesValid range: -90.0 to 90.0
- Positive values represent North
- Negative values represent South
The longitude coordinate in decimal degreesValid range: -180.0 to 180.0
- Positive values represent East
- Negative values represent West
Usage Examples
Creating a DeviceLocation instance
Creating from Google Maps Location
Creating from LocationRepository
Data Class Features
As a Kotlin data class,DeviceLocation automatically provides:
- equals(): Compares two locations based on coordinates
- hashCode(): Generates hash code based on coordinates
- toString(): Returns a string representation of the location
- copy(): Creates a copy with optionally modified coordinates
- componentN(): Enables destructuring declarations
Destructuring
Validation
Formatting
Decimal degrees format
Degrees, Minutes, Seconds format
Distance Calculation
Haversine formula for distance between two locations
Google Maps Integration
Converting to LatLng
Creating marker
Common Locations
Source Location
com.demodogo.ev_sum_2.domain.models.DeviceLocation