Using JSON APIs from within an Action

This was a little challenge I set for myself, and I was very pleased with how it worked out. I just released an Action for Open Street Map, and unlike the Google Map, you can’t just use random place names when requesting a map – you need a proper lat/long pair or you don’t get anything.

Here’s the code:

function search(){
  var address = fwParameters['address'].fwValue;
  if(address.length < 1) return;
  var location = fwShellCommand('curl -d -H "Accept: application/json" "http://nominatim.openstreetmap.org/search?q=' + escape(address) + '&format=json&limit=1"');
  location = eval(location.toString())[0];
  if(undefined == location){
    fwAbort('Could not locate that address');
  }else{
    fwParameters['Latitude'].fwValue = location.lat;
    fwParameters['Longitude'].fwValue = location.lon;
  }
}

This is called from the onclick handler of an , and it grabs the current address, sticks it into a JSON request, and uses cURL to send that to the API endpoint. Response is parsed and injected into the Action fields, and there is great rejoicing.

The only thing missing from a perfect UX is some sort of “wait state cursor” to show that the request is in process. If anyone has any suggestions, I would appreciate that.

Walter


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Good work Walter. I’ve done a few things like this in the past (asking the Finder for a quick look preview of a selected file in an Action control for example) and I found that Freeway pretty much stopped while the shell command was running which made updating the UI impossible. It’d be great if we could add in something (even a ‘please wait’ label) so the user knows that the Action is off gathering data and not simply crashed.
Regards,
Tim.

On 9 Apr 2014, at 16:41, Walter Lee Davis wrote:

The only thing missing from a perfect UX is some sort of “wait state cursor” to show that the request is in process. If anyone has any suggestions, I would appreciate that.


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I was going to suggest ASObjC Runner as an option - I use it in a couple of AppleSCripts here to show progress. But it seems that support is stopping with Mavericks, so this may have limited appeal.

http://www.macosxautomation.com/applescript/apps/runner.html

Unfortunately, I just don‘t get the AppleScriptObjC-based libraries thing they are talking about, but then Apple have been slowly putting me off AppleScript for a few years with their move from what was a fairly easy and understandable way to build a simple app to something which appears to need a degree in computer science (hence my recent interest in LoveCode).


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I hope the is action is still “live” (Freeway Pro 7.1.3)?

As a refugee from Google Maps (not happy about giving credit card details to the big G) this looks an ideal replacement, especially as I love OpenStreetMap and am a contributor.

I’ve had a try running this action (running FreewayPro 7.1.3 but can’t get it to accept any address or Long/Lat details. Is there a guide for what the action expects to receive? I’m in the UK so have tried postal (number/street/town) and postcodes plus N50º W005º type Long/Lat numbers but get an error box every time. Error underlines in red: “location=eval(location.toString())[0];” as near as I can make out (very small type)

I’ve tried Lat/Lon in many formats e.g.
N5009238
N50.09.238
N50 09 238
(and Longitude co-ords as well)

When I go to “publish”, all return a “Map Coordinates invalid” and a blank page.

Cross posted to Actions Forge.

Thanks for any response.


actionsdev mailing list
email@hidden
Update your subscriptions at:

Fixed there, too. The issue was getting the correct format of geocoding data to enter in the interface.

Walter

On Aug 8, 2018, at 9:49 AM, xgraphica email@hidden wrote:

Cross posted to Actions Forge.


actionsdev mailing list
email@hidden
Update your subscriptions at:
https://freewaytalk.softpress.com/person/options