I was playing around with the Nominatim API from Openstreetmap to do a reverse location search for templates (using the New Draft with Template Action) . I was stumbling over the following issue; if I have no Draft open and create a temporary draft to retrieve the location data like so:
let d = new Draft();
let lat = d.createdLatitude();
let lon = d.createdLongitude();
lon return always
0.0. If I’ve a draft open and retrieve the location like this:
let lat = draft.createdLatitude();
let lon = draft.createdLongitude();
I’ll get data, but if there is no draft open it’ll return also just
Is this intended that
new Draft(); does not add location data to the draft?.
That is intended. A new draft does not exist until it is saved, and that is when timestamps and location information is saved.
There’s not a scripted property to get the current location information - probably should be, will make a note - but you can get it via the template engine.
[[latitude]] return the current values, so you could do:
let lat = draft.processTemplate("[[latitude]]")
let lon = draft.processTemplate("[[longitude]]")
d.update() on your temp draft to save it and then those values should exist. You can call update again later in the script after making additional changes.
Ah okay, I read about the template tags option once, but I thought I have to have the tags in the template then in order to use them and I had ‘d.update()’ in there, removed it due to another issue and forgot to put it back to test it.
Thanks for the quick support.