Skip to content

Commit

Permalink
Add a name when a custom place doesn't have one
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Chagas <[email protected]>
  • Loading branch information
rtchagas committed May 20, 2020
1 parent 6b55894 commit c015d4d
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,22 @@ class GoogleMapsRepository constructor(

val latLng = LatLng(place.geometry.location.lat, place.geometry.location.lng)

val address =
val address: String =
if (place.formattedAddress.isNotEmpty()) place.formattedAddress
else place.vicinity

return CustomPlace(place.placeId, place.name, photoList, address, typeList, latLng)
val name: String = buildPlaceName(place.name, address)

return CustomPlace(place.placeId, name, photoList, address, typeList, latLng)
}

private fun buildPlaceName(originalName: String, address: String): String {
// We have a nice name, use it
if (originalName.isNotEmpty()) {
return originalName
}
// Return the first part of the address, usually the street + number
return address.split(",").first()
}

/**
Expand Down

0 comments on commit c015d4d

Please sign in to comment.