Skip to content

Instantly share code, notes, and snippets.

@brucemcpherson
Created October 4, 2012 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brucemcpherson/3834515 to your computer and use it in GitHub Desktop.
Save brucemcpherson/3834515 to your computer and use it in GitHub Desktop.
pseudo api using google content service to mashup urbarama
// this will return data from urbarama mashup of geocoding an urbarama query
// api?address=someaddressneedinggeocoding&within=numberofkilometersfromaddress
function doGet(e) {
return ContentService
.createTextOutput(JSON.stringify (urbaramaMashup(e)))
.setMimeType(ContentService.MimeType.JSON);
}
function urbaramaMashup(e) {
// lets decode the arguments
var content = null ;
if (!e.parameter) {
content = {error: "parameters not found"} ;
}
else if (!e.parameter.address) {
content = {error: "address parameter not found", parameters : e } ;
}
else {
// geocode it
var s = e.parameter.address;
// default 20 kms
var d = e.parameter.within ? mcpher.CDbl (e.parameter.within) : 20;
var cr = mcpher.restQuery(undefined, "yahoo geocode", s, false,
undefined ,undefined , undefined, false, undefined, false) ;
if(cr) {
try {
var lat = mcpher.CDbl(cr.jObject().find("latitude").value()) ;
var lon = mcpher.CDbl(cr.jObject().find("longitude").value()) ;
}
catch (err) {
content = {error: "could not geocode " + s, errormessage : err, parameters : e } ;
}
if (!content) {
// still no errors.. press on
var cru = mcpher.generalQuery(undefined, "urbarama",
"&miny=" + mcpher.CStr(mcpher.getLatFromDistance(lat, d, -135)) +
"&minx=" + mcpher.CStr(mcpher.getLonFromDistance(lat, lon, d, -135)) +
"&maxy=" + mcpher.CStr(mcpher.getLatFromDistance(lat, d, 45)) +
"&maxx=" + mcpher.CStr(mcpher.getLonFromDistance(lat, lon, d, 45)), false,
undefined ,undefined , undefined, false, undefined, false) ;
}
if (!cr) {
content = {error: "unable to query " + e.parameter.shortname, parameters: e } ;
}
else {
content = cru.jObject().toNative();
}
}
else {
content = {error: "could not get geocode rest entry", parameters : e } ;
}
}
return content;
}
// just a tester
function t() {
var e = { parameter:
{address : "london",
within : 10
}
};
Logger.log(JSON.stringify(urbaramaMashup(e)));
}
@brucemcpherson
Copy link
Author

for more information see ramblings.mcpher.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment