Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/geosearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { request, App, Notice } from 'obsidian';
import * as geosearch from 'leaflet-geosearch';
import * as leaflet from 'leaflet';
import queryString from 'query-string';

import { readFileSync } from 'fs';
import { type PluginSettings } from 'src/settings';
import { UrlConvertor } from 'src/urlConvertor';
import { FileMarker } from 'src/fileMarker';
Expand Down Expand Up @@ -45,9 +45,12 @@ export class GeoSearcher {
},
});
} else if (settings.searchProvider == 'google') {
this.searchProvider = new geosearch.GoogleProvider({
apiKey: settings.geocodingApiKey,
});
const apiKey =
settings.geocodingApiMethod === 'key'
? settings.geocodingApiKey
: readFileSync(settings.geocodingApiPath, 'utf-8').trim();

this.searchProvider = new geosearch.GoogleProvider({ apiKey });
}
}

Expand Down Expand Up @@ -132,7 +135,9 @@ export async function googlePlacesSearch(
): Promise<GeoSearchResult[]> {
if (settings.searchProvider != 'google' || !settings.useGooglePlacesNew2025)
return [];
const googleApiKey = settings.geocodingApiKey;
const googleApiKey = settings.geocodingApiMethod === 'key'
? settings.geocodingApiKey
: readFileSync(settings.geocodingApiPath, 'utf-8').trim();

// Request body for the new Places API
const requestBody = {
Expand Down
3 changes: 3 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export type PluginSettings = {
searchProvider: 'osm' | 'google';
osmUser: string;
searchDelayMs: number;
geocodingApiMethod?: 'key' | 'path';
geocodingApiKey: string;
geocodingApiPath?: string;
useGooglePlacesNew2025: boolean;
googlePlacesDataFields: string;
saveHistory: boolean;
Expand Down Expand Up @@ -284,6 +286,7 @@ export const DEFAULT_SETTINGS: PluginSettings = {
searchProvider: 'osm',
osmUser: '',
searchDelayMs: 250,
geocodingApiMethod: 'key',
geocodingApiKey: '',
useGooglePlacesNew2025: false,
googlePlacesDataFields: '',
Expand Down
Loading