From 35435296003f6de9229b30a4998fa3cea8443fee Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Fri, 6 Sep 2024 13:02:12 +0200 Subject: [PATCH] Add GPS coordinate as wgs84 tag --- main.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/main.ts b/main.ts index 7699336..0afc4ca 100644 --- a/main.ts +++ b/main.ts @@ -92,6 +92,7 @@ for (const i in posts) { // Populated from the first media item with coordinates let geotags; + let event_tags: string[][] = []; let first = true; for (const j in post.media) { @@ -146,15 +147,20 @@ for (const i in posts) { iso31663: false }; - let exif_data = media.media_metadata.photo_metadata.exif_data; + const exif_data = media.media_metadata.photo_metadata.exif_data; if (exif_data) { for (const k in exif_data) { const exif_item = exif_data[k]; if (exif_item.latitude != undefined && exif_item.latitude != undefined) { - geotags = ngeotags({ + // Add coordinates as a tag. + // There is currently no NIP defining a wgs84 tag! + event_tags.push(['wgs84', String(exif_item.latitude), String(exif_item.longitude)]) + // Encode coordinates as Geohash in different resolutions: + // https://en.wikipedia.org/wiki/Geohash + event_tags = [...event_tags, ...ngeotags({ lat: exif_item.latitude, lon: exif_item.longitude - }, options); + }, options)]; } } } @@ -165,12 +171,9 @@ for (const i in posts) { let event = { kind: 1, content: message, - tags: [], + tags: event_tags, created_at: created_at } - if (geotags != undefined) { - event.tags = [...event.tags, ...geotags]; - } const signed_event = await signer.signEvent(event); console.log(signed_event); events.push(signed_event);