In Urbarama mashup we looked at how to mashup mutiple APIS and serve up the result. Now we are going to use that to further enhance and publish the results. 
The problem with the Urbarama api is that it returns places of interest within a box of a given latitude/longitude. If we want instead to only return items within a given distance of the origin, we need to work with a circle radius instead, and discard anything that is in the box, but outside the circle.

In Delegation to Google Apps Script we have already created an urbenhanced script. Here’s the code you need to paste in:

What’s happening here

Looking at the urbFilterCircle function,

  • urbGetResults executes the urbarama mashup as rest query, and gets the jSon results.
  • if that works, then we need to re geocode the address. It will already have been done in urbarama mashup, but it is not something that it returns. So we’ll call the yahoo geocoder to do it again. Another alternative would have been to add this property to the original mashup, but I’m also using this example to illustrate the use of the rest library to do queries that already exist. urbGeoRest() simply asks the rest library, which is in the mcpher library, to do a geocoding. Note that all queries initiated by the mcpher library use the Google Cache service. This means that result of this query, previously done, will anyway be in cache.
  • if that worked, the we create a new array of qualifying addresses by comparing the distance between their co-ordinates and the origin, discarding those that are out of range.

Testing

TestUrb is provided to check the results before publishing. We can see from a query using London as the origin and a radius of 20km, that we discard 5 entries as being within the bounding box, but outside the radius.

Publishing

Now we are ready to publish the app, just as we did with Hosting your public scriptdb. My version of this is published at

https://script.google.com/a/macros/mcpher.com/s/AKfycbxvzTqn3fmW0SOdSOYqjwZh0itY066XhPb7YmHkDaztKOgX6Cqd/exec?entry=london&within=20

and is shown here with a couple of parameters.

Now take a look at the next step in step by step guide to delegating to Google Apps Script.