-
Notifications
You must be signed in to change notification settings - Fork 50
Use Google Maps Place data in templates #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thank you for this contribution, users will love it. |
|
Sure! Do you think unresolvable paths should be left as |
Let me know your comments, I cant see them atm |
manifest.json
Outdated
| { | ||
| "id": "obsidian-map-view", | ||
| "name": "Map View", | ||
| "id": "obsidian-map-view-dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove from the PR
src/geosearch.ts
Outdated
| location: leaflet.LatLng; | ||
| resultType: 'searchResult' | 'url' | 'existingMarker'; | ||
| existingMarker?: FileMarker; | ||
| extraLocationData?: object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make a more specific type here, e.g. define the fields expected from the Google Places API?
src/geosearch.ts
Outdated
| name: `${result?.name} (${result?.formatted_address})`, | ||
| location: geolocation, | ||
| resultType: 'searchResult', | ||
| extraLocationData: { google_maps_place_data: result }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for using the underscore convention here, which is not consistent with the rest of the code? Rather than googleMapsPlacesData?
src/utils.ts
Outdated
|
|
||
| export function formatWithTemplates(s: string, query = '') { | ||
| function resolveJsonPath(json: object, path: string): string { | ||
| // convert a string path like "some.path.to.data.0" to the value at that path in json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capital C in 'convert' please, capitals in JSON
src/utils.ts
Outdated
| // Use regex to find all patterns like {{some.path.to.data.0}} | ||
| return inputString.replace(/{{(.*?)}}/g, (_, path: string) => { | ||
| const value = resolveJsonPath(json, path); | ||
| // return value !== undefined ? value : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this line is redundant, please remove
src/utils.ts
Outdated
| let templateContent = ''; | ||
| if (templatePath && templatePath.length > 0) | ||
| templateContent = await app.vault.adapter.read(templatePath); | ||
| console.log('extraLocationData:'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove these logs
So sorry, I forgot to submit the comments after writing them 🤦 |
|
I've added the google maps typing package so I can type annotate with |
|
Looks great, thank you! |
|
I was about to ask if anyone had done this. |
Currently only new notes use this new template variable ( obsidian-map-view/src/utils.ts Line 143 in 1e0ecca
obsidian-map-view/src/utils.ts Line 270 in 1e0ecca
|
I really like this plugin and I've been using Templater to query the Google Maps Place API and automatically fill in details like:
restaurant,cafe, etc ...)place_idso I can build a direction URL and a search URL (https://developers.google.com/maps/documentation/urls/get-started)nameattribute.Same issue as #173
Solution
A template can contain paths to data returned in the full Google Maps places data
It would be easy to extend the solution to OSM.
Example
With this template:
A query to Katz's Delicatessen results in this note:

Undefined paths return the empty string.
Updating current notes without `place_id`
I'm using Templater to update my old geo tagged places that don't have this extra information. In my startup template I have: