1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-02 19:55:18 +02:00

Implement reverse geocoding search functionality and update type definitions

This commit is contained in:
Sean Morley 2025-05-24 14:12:06 -04:00
parent ec2b285d50
commit 042d034594
5 changed files with 44 additions and 32 deletions

View file

@ -1,7 +1,7 @@
<script lang="ts">
import { appVersion } from '$lib/config';
import { addToast } from '$lib/toasts';
import type { Adventure, Lodging, OpenStreetMapPlace, Point, ReverseGeocode } from '$lib/types';
import type { Adventure, Lodging, GeocodeSearchResult, Point, ReverseGeocode } from '$lib/types';
import { onMount } from 'svelte';
import { t } from 'svelte-i18n';
import { DefaultMarker, MapEvents, MapLibre } from 'svelte-maplibre';
@ -19,7 +19,7 @@
let willBeMarkedVisited: boolean = false;
let previousCoords: { lat: number; lng: number } | null = null;
let old_display_name: string = '';
let places: OpenStreetMapPlace[] = [];
let places: GeocodeSearchResult[] = [];
let noPlaces: boolean = false;
onMount(() => {
@ -167,13 +167,9 @@
alert($t('adventures.no_location'));
return;
}
let res = await fetch(`https://nominatim.openstreetmap.org/search?q=${query}&format=jsonv2`, {
headers: {
'User-Agent': `AdventureLog / ${appVersion} `
}
});
let res = await fetch(`/api/reverse-geocode/search/?query=${query}`);
console.log(res);
let data = (await res.json()) as OpenStreetMapPlace[];
let data = (await res.json()) as GeocodeSearchResult[];
places = data;
if (data.length === 0) {
noPlaces = true;

View file

@ -1,6 +1,6 @@
<script lang="ts">
// @ts-nocheck
import type { Adventure, OpenStreetMapPlace, Point } from '$lib/types';
import type { Adventure, GeocodeSearchResult, Point } from '$lib/types';
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
import { onMount } from 'svelte';
@ -50,7 +50,7 @@
}
}
let places: OpenStreetMapPlace[] = [];
let places: GeocodeSearchResult[] = [];
async function geocode(e: Event | null) {
if (e) {
@ -60,13 +60,9 @@
alert('Please enter a location');
return;
}
let res = await fetch(`https://nominatim.openstreetmap.org/search?q=${query}&format=jsonv2`, {
headers: {
'User-Agent': `AdventureLog / ${appVersion} `
}
});
let res = await fetch(`/api/reverse-geocode/search/?query=${query}`);
console.log(res);
let data = (await res.json()) as OpenStreetMapPlace[];
let data = (await res.json()) as GeocodeSearchResult[];
places = data;
}

View file

@ -81,7 +81,7 @@
}
const fetchLocation = async (query: string) => {
let res = await fetch(`https://nominatim.openstreetmap.org/search?q=${query}&format=jsonv2`, {
let res = await fetch(`/api/reverse-geocode/search/?query=${query}`, {
headers: {
'User-Agent': `AdventureLog / ${appVersion} `
}

View file

@ -139,21 +139,15 @@ export type Collection = {
link?: string | null;
};
export type OpenStreetMapPlace = {
place_id: number;
licence: string;
osm_type: string;
osm_id: number;
lat: string;
lon: string;
category: string;
type: string;
place_rank: number;
importance: number;
addresstype: string;
name: string;
display_name: string;
boundingbox: string[];
export type GeocodeSearchResult = {
lat?: string;
lon?: string;
category?: string;
type?: string;
importance?: number;
addresstype?: string;
name?: string;
display_name?: string;
};
export type Transportation = {