Skip to content

Conversation

@missuo
Copy link

@missuo missuo commented Sep 5, 2025

Summary

This PR enhances the display of location information by showing the geographical name instead of just raw latitude and longitude coordinates. It integrates the free [Nominatim](https://nominatim.org/) API to perform reverse geocoding.

For a detailed preview of the changes, please refer to: https://vincent.ac/IMG_0306


Changes

  • Feature: Use the Nominatim API to fetch human-readable geographical names based on latitude and longitude.

  • UI Update: Locations are now displayed as descriptive names when available, improving readability and user experience.

  • New Environment Variables:

    • NOMINATIM_ACCEPT_LANGUAGE → Sets the preferred language for location names.

      • Default: en
    • VITE_SHOW_DETAILED_LOCATION → Controls the granularity of the displayed location:

      • If set to true, shows detailed location names (e.g., street, neighborhood, etc.).
      • If set to false, only shows the city-level location.
      • Default: false

…ystem

Add comprehensive location processing pipeline including EXIF GPS extraction,
coordinate validation, and Nominatim reverse geocoding with caching support.
Enhance photo metadata with location data and improve ExifPanel display.
Add geocode cache file to .gitignore to exclude generated data from tracking.
- Updated Nominatim reverse geocoding to include a display name in the response.
- Modified the ExifPanel to conditionally show detailed location based on the new environment variable.
- Adjusted location formatting logic to accommodate East Asian language order.
- Added displayName field to relevant types and processing functions for improved location representation.
Comment on lines +6 to +8

NOMINATIM_ACCEPT_LANGUAGE=en
VITE_SHOW_DETAILED_LOCATION=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using config.json instead of env? https://github.com/Afilmory/afilmory/blob/main/config.example.json

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or builder.config.json

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove this since we already use config.json

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use builder.config.json instead

@@ -0,0 +1,36 @@
import type { PickedExif } from '../../types/photo.js'

export function convertExifGPSToDecimal(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i remember there is already a function for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use convertExifGPSToDecimal in apps/web/src/lib/map-utils.ts ?

if (existing) return existing

const p = schedule(async () => {
const url = `https://nominatim.openstreetmap.org/reverse?lat=${encodeURIComponent(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://operations.osmfoundation.org/policies/nominatim/ nominatim requires a 1 qps limit for its api

- Introduced geocoding settings in builder and site configurations, allowing for customizable language preferences.
- Updated ExifPanel to utilize site configuration for displaying detailed location based on user settings.
- Enhanced example configuration files to reflect new options for geocoding and UI display preferences.
@missuo
Copy link
Author

missuo commented Sep 6, 2025

I have fixed the above issues. acceptLanguage is placed in builder.config.json, while showDetailedLocation, which controls the rendering of the front-end page, is placed in config.json.

Also, the frequency of requests to the Nominatim API has been strictly controlled.

Please check the code again, thank you.

@Innei Innei requested a review from Enter-tainer September 8, 2025 12:36
Comment on lines +6 to +8

NOMINATIM_ACCEPT_LANGUAGE=en
VITE_SHOW_DETAILED_LOCATION=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove this since we already use config.json

Comment on lines +64 to +67
const isEastAsiaOrder =
activeLang.startsWith('zh') ||
activeLang.startsWith('ja') ||
activeLang === 'jp'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about ko?

Comment on lines +64 to +67
const isEastAsiaOrder =
activeLang.startsWith('zh') ||
activeLang.startsWith('ja') ||
activeLang === 'jp'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ja or jp?

Comment on lines +75 to +76
return isEastAsiaOrder ? parts.join(' ') : parts.join(', ')
}, [currentPhoto])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc in China we don't use space to separate address. like 辽宁省沈阳市. But i guess depends on the result of the api call. I'm open to discussion.

address?: Record<string, string>
}

const CACHE_FILE = path.join(workdir, 'src/data/.geocode-cache.json')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO for reviewer: why do we need a new cache file. Any recommendation? Would it be possible to directly use manifest

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @Innei


type NominatimResponse = {
display_name?: string
address?: Record<string, string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider using a more accurate type hint for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to use manifest, scanning the corresponding fields in builder can detect whether cache data exists.

}
}

const roundCoord = (n: number, decimals = 3) => Number(n.toFixed(decimals))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 3?

Comment on lines +232 to +237
location: await processLocation(
exifData,
photoKey,
existingItem,
options,
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an option to disable reverse geoencoding. Due to the rate limit, it would be extremely slow to build manifest for users with many photos

@Innei
Copy link
Contributor

Innei commented Sep 13, 2025

@codex review code and summary this pr changes, what feature want to implement?

@chatgpt-codex-connector
Copy link

@codex review code and summary this pr changes, what feature want to implement?

For now, I can only help with PRs you've created.

@Innei
Copy link
Contributor

Innei commented Sep 13, 2025

@copilot review code and summary this pr changes, what feature want to implement?

Comment on lines +6 to +8

NOMINATIM_ACCEPT_LANGUAGE=en
VITE_SHOW_DETAILED_LOCATION=true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use builder.config.json instead

apps/web/assets-git
apps/web/public/thumbnails
apps/web/src/data/photos-manifest.json
apps/web/src/data/.geocode-cache.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.geocode-cache.json should upload to remote repo cache


type NominatimResponse = {
display_name?: string
address?: Record<string, string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to use manifest, scanning the corresponding fields in builder can detect whether cache data exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants