Use Google Maps Place data in templates#294
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", |
src/geosearch.ts
Outdated
| location: leaflet.LatLng; | ||
| resultType: 'searchResult' | 'url' | 'existingMarker'; | ||
| existingMarker?: FileMarker; | ||
| extraLocationData?: object; |
There was a problem hiding this comment.
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.
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.
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.
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:'); |
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: