This Android application calculates the distance between two geographic locations using the Haversine formula. The app allows users to select starting and ending locations via Google Places Autocomplete interface, and then calculates the distance between these points.
- Google Places Autocomplete integration for location selection
- Geographic coordinate display for selected locations
- Distance calculation using the Haversine formula
- Simple and intuitive user interface
- Android Studio
- Google Places API key
- Android SDK
- Clone the repository
- Open the project in Android Studio
- Replace the Google Places API key in the
Places.initialize()
method with your own API key - Build and run the application on your device or emulator
- Launch the application
- Tap on the "Start Location" field to select your starting point using the Google Places Autocomplete interface
- Tap on the "End Location" field to select your destination using Google Places Autocomplete
- Press the "Calculate" button to compute the distance between the two locations
- View the result along with the geographic coordinates of both locations
MainActivity.kt
: Main activity handling user interaction and calculationHaversineAlgorithm.kt
: Utility class that implements the Haversine formulaGlobalFunction.kt
: Helper functions for storing location dataactivity_main.xml
: Main layout file for the UI
The Haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes. It is particularly useful for calculating distances between points on the Earth.
- Google Play Services Places API
- AndroidX AppCompat
The application uses SharedPreferences to store location data:
- Start location coordinates are stored with keys defined in
R.string.LAT_START
andR.string.LNG_END
- End location coordinates are stored with keys defined in
R.string.LAT_END
andR.string.LNG_END