Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
36 lines (29 sloc)
1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = async (params) => { | |
| const {createYamlProperty} = params.app.plugins.plugins["metaedit"].api; | |
| const address = await params.quickAddApi.inputPrompt("🏠 Address"); | |
| if (!address) { | |
| new Notice("No address given", 5000); | |
| return; | |
| } | |
| const result = await apiGet(address); | |
| if (!result.length) { | |
| new Notice("No results found", 5000); | |
| return; | |
| } | |
| const {lat, lon} = result[0]; | |
| const activeFile = params.app.workspace.getActiveFile(); | |
| if (!activeFile) { | |
| new Notice("No active file", 5000); | |
| return; | |
| } | |
| await createYamlProperty("location", `[${lat}, ${lon}]`, activeFile); | |
| } | |
| async function apiGet(searchQuery) { | |
| let finalURL = new URL(`https://nominatim.openstreetmap.org/search?q=${searchQuery}&format=json`); | |
| return await fetch(finalURL, { | |
| method: 'GET', cache: 'no-cache', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| }).then(async (res) => await res.json()); | |
| } |