-
-
Notifications
You must be signed in to change notification settings - Fork 616
Description
Describe the feature
Description
In the Memories section, location-type memories currently display plain geocodes when the image coordinates are not near any of the predefined popular places listed in CITY_COORDINATES within memory_clustering.py.
Instead of showing raw latitude/longitude values, the application can display the nearest local place name (city/town/village) derived from the image’s geocodes.
If the distance to the nearest locality exceeds a configurable threshold (default: 4.0 km), only the state name should be displayed rather than plain geocodes.
Current Problem
- When image geocodes do not match nearby entries in
CITY_COORDINATES, the UI displays raw latitude/longitude values. - Plain geocodes are not user-friendly and reduce the overall UX quality.
- Users cannot easily interpret the actual location represented by the coordinates.
Expected Feature
- Determine the nearest locality (city/town/village) using reverse geocoding.
- Display the local place name instead of plain geocodes.
- If the nearest locality is farther than the threshold distance (default: 4.0 km):
- Display only the state name.
- Avoid showing raw coordinates.
- Determination of nearest locality using reverse geocoding should be offline.
Implementation
Backend
-
Added
GeoCodes.dbfile. It contains tables for all States and Union Territories, with approximately 500 cities/towns/villages per state. (Currently India)
-The database also includes aclassifiertable used to determine which state should be searched for a given set of geocodes. (Example: For provided coordinates, the classifier predicts the most probable state where the location belongs.)- Table Columns:
states: place | latitude | Longitudeclassifier: state | latitude | Longitude
- Table Columns:
-
Implemented the Haversine formula to compute distances and identify the nearest locality (city/town/village) within the predicted state
-
Updated return values of function
_reverse_geocodeinmemories_clustering.pyas:
def _reverse_geocode(self, lat: float, lon: float) -> Optional[str]: # added optional return
"""Find nearest city within 50km"""
for city_name, (city_lat, city_lon) in self.CITY_COORDINATES.items():
distance = haversine_distance(lat, lon, city_lat, city_lon)
if distance < 50:
return city_name, True # True -> because city name found
return f"{lat:.4f}°, {lon:.4f}°", False # False -> because of formatted coordinates- Updated return value in function
_create_simple_memoryinmemories_clustering.pyas:
# Get actual location name using reverse geocoding
location_name, status = self._reverse_geocode(center_lat, center_lon) # status is true if nearest tourist place (actual location) is found
if not status:
# getting place name if no nearest tourist place found
place = get_location_by_geocode(latitude=center_lat, longitude=center_lon, offset=4.0)
else:
place = None
return {
"memory_id": memory_id,
"title": title,
"description": f"{len(images)} photos",
"location_name": location_name,
"place":place, # added key value pair for place
"date_start": date_start,
"date_end": date_end,
"image_count": len(images),
"images": sorted_images,
"thumbnail_image_id": sorted_images[0].get("id", ""),
"center_lat": center_lat,
"center_lon": center_lon,
"type": memory_type,
}-
Updated Memory Schemas in
routes/memories.pyfor new key. -
added
!GeoCodes.dbin .gitignore
Frontend
- Modified
memories.tsto include theplace: string | nullfield in theMemoryinterface
place: string | null;- Updated MemoryCard Component:
- Added logic in Memories/MemoryCard.tsx, to override the
displayTitlewith the value ofplaceif it is available.
// If "place" is provided (from backend), use it as the main title if (memory.place) { displayTitle = memory.place; }
- Added logic in Memories/MemoryCard.tsx, to override the
- Updated MemoryDetail Component:
- Updated the
tempMemoryobject for the "On This Day" feature to include theplacefield. - Synchronized the
displayTitlelogic inMemoryDetail.tsxwithMemoryCard.tsxto ensure consistency between the list view and the detail view.
- Updated the
Add ScreenShots
Screenshots
Before
After
Record
- I agree to follow this project's Code of Conduct
- I want to work on this issue



