Reverse geocode feature?

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.

1 Like

The results from Shortcuts (used in another context) have been fine for me. Maybe they’re better now?

1 Like

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);
}
1 Like