enviroCar / enviroCar-app

enviroCar Android Application
https://envirocar.org
GNU General Public License v3.0
89 stars 158 forks source link

Added `LocationIndicator` in `org.envirocar.map` module to display current user location #1006

Closed alexmercerind closed 4 months ago

alexmercerind commented 4 months ago

This pull-request adds LocationIndicator to display current user location in the org.envirocar.map module, in a provider independent manner. Several new classes have been introduced:

A video for reference is attached below:

https://github.com/user-attachments/assets/81c0a474-8a64-400c-b287-2238218f9f5d

Implementation

%%{
  init: {
    'themeVariables': {
      'fontFamily': 'BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Arial, Apple Color Emoji, Segoe UI Emoji'
    }
  }
}%%
classDiagram

BaseLocationIndicator <|-- LocationIndicator
`android.location.LocationListener` <|.. LocationIndicator
LocationIndicator *-- `android.location.LocationManager`

class BaseLocationIndicator {
    +enable()
    +disable()
    +setCameraMode(value: LocationIndicatorCameraMode)
    +notifyLocation(location: Location)
    -followCameraIfRequired(location: Location)
    -clearMarkers()
    -clearPolygons()
}

class LocationIndicator {
    +enable()
    +disable()
    +onLocationChanged()
}

The LocationIndicator may be used to display the current location on the map. It internally creates an instance of LocationManager from Android API, to listen to the location updates from the device.

The LocationIndicator inherits from another class called BaseLocationIndicator, which can be used to display the supplied location on the map, through the notifyLocation method. The LocationManager inside the LocationIndicator requests the location updates from the device, causing onLocationChanged callback to be invoked, which internally calls notifyLocation from BaseLocationIndicator to draw the current location. Inside the enviroCar application, it makes more sense to use BaseLocationIndicator directly, since location updates are already sent through the event bus & creating another LocationManager will be redundant.

SebaDro commented 4 months ago

Superseded by #1007