I would love to have some kind of reverse geocode function for HTML preview displays of notes. In other words, take the geocoded coordinates of a particular draft and provide some method or function for getting back an address or place name, which could then be displayed in an HTML preview of the note. Scriptable has this feature, or I suppose shortcuts, but I’d prefer to just stay in drafts for this rather than bouncing back and forth (the main script I want to use this on scans upwards of 20 drafts to create a single HTML preview window and I think it would be too much to go back and forth between apps for this)
I’ll put it on the list to consider adding wrappers to those APIs. It’s been a while since I used Apple’s reverse geocoder, but I don’t remember the results being great…perhaps they have improved over time.
There are many online APIs to do geocoding as well that could be directly accessed within Drafts with HTTP
scripting. Might be worth pursuing.
The results from Shortcuts (used in another context) have been fine for me. Maybe they’re better now?
if anyone is curious to play with this, I hacked this together using PositionStack:
// geocode sample
let q = draft.createdLatitude + "," + draft.createdLongitude;
var http = HTTP.create(); // create HTTP object
var response = http.request({
"url": "http://api.positionstack.com/v1/reverse",
"method": "GET",
"parameters": {
"access_key": "yourkeygoeshere",
"query": q
}
});
if (response.success) {
var text = response.responseText;
console.log(text);
let geodata = JSON.parse(text);
let label = geodata.data[0].name;
alert(label);
}
else {
console.log(response.statusCode);
console.log(response.error);
}
I’d love something like this native to drafts… even “just to the City, State level.” I use drafts to start notes that are then moved to OneNote… and having the city and state listed would help to remember where the note was taken and its context.
I figured out a code to get this done:
// geocode sample Taken from several sources on Draft community and some assistance from ChatGPT AI - DHT 2023-03-05 Sun
let q = draft.createdLatitude + "," + draft.createdLongitude;
let tm1 = draft.createdAt;
var http = HTTP.create(); // create HTTP object
var response = http.request({
"url": "http://api.positionstack.com/v1/reverse",
"method": "GET",
"parameters": {
"access_key": "[YourAccessKeyFromPositionStack]",
"query": q
}
});
if (response.success) {
var text = response.responseText;
console.log(text);
// alert (text);
let geodata = JSON.parse(text);
let llabel = geodata.data[0].name;
let rregion = geodata.data[0].region;
let nnhood = geodata.data[0].locality;
// Get the variables from https://positionstack.com/documentation
// alert(llabel);
// alert(nnhood);
// alert(rregion);
// append current draft;
let d = draft;
d.content = "Near " + llabel + " " + nnhood + " " + rregion + " at " + tm1 +"\n" + d.content;
d.update();
}
else {
console.log(response.statusCode);
console.log(response.error);
}