getLocationName method

String getLocationName()

Utility function to get clean readable name of a location. First checks for a human-readable name from the nearby list. This helps in the cases that the user selects from the nearby list (and expects to see that as a result, instead of road name). If no name is found from the nearby list, then the road name returned is used instead.

Implementation

String getLocationName() {
  if (this.locationResult == null) {
    return widget.localizationItem!.unnamedLocation;
  }

  for (NearbyPlace np in this.nearbyPlaces) {
    if (np.latLng == this.locationResult?.latLng &&
        np.name != this.locationResult?.locality) {
      this.locationResult?.name = np.name;
      return "${np.name}, ${this.locationResult?.locality}";
    }
  }

  return "${this.locationResult?.name}, ${this.locationResult?.locality}";
}