## 4/24/2010

Recently became available scripts in Google Spreadsheets for personal accounts (gmail).
Abstract
In addition, we can publish scripts in the gallery.
Now we can create scripts for Google Spreadsheets, upload, post, communicate with other users.
Scripts have a rich set of features. We can use all the management services available in Google.

The result of the script, for example, may be:
• new function;
• value returned by the Web service, including, SOAP, WSDL, and others;
• management of other services, such as website, calendar, mailing;
• automatic filling of tables (direct control of our spreadsheets);
• creation of user interfaces (custom spreadsheets UI).

Examples of scripts in neogeography

Great Circle Distance between points
`Copy Source | Copy HTML`
`function GCD1(lat1, lon1, lat2, lon2) {// Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len;}​ `
Geocoding
Return KML by placename
`Copy Source | Copy HTML`
`function getKML(placeName) {// Return KML by placename if (placeName == "") { return "You have to write the name the place" } var url = "http://maps.google.com/maps/geo?q="+ placeName+"&output=kml"; var response = UrlFetchApp.fetch(url); var str = response.getContentText(); return str;} `
Return Longitude and Latitude by placename
`function getLngLat(placeName) {// Return LngLatitude by placename if (placeName == "") { return "You have to write the name the place" } var url = "http://maps.google.com/maps/geo?q="+ placeName+"&output=json"; var response = UrlFetchApp.fetch(url); var str=eval('(' + response.getContentText() + ')').Placemark[ 0].Point.coordinates; return str;} `
Return Longitude by placename
`function getLng(placeName) {// Return Longitude by placename if (placeName == "") { return "You have to write the name the place" } var url = "http://maps.google.com/maps/geo?q="+ placeName+"&output=json"; var response = UrlFetchApp.fetch(url); var str=eval('(' + response.getContentText() + ')').Placemark[ 0].Point.coordinates[ 0]; return str;} `
Return Latitude by placename
`function getLat(placeName) {// Return Latitude by placename if (placeName == "") { return "You have to write the name the place" } var url = "http://maps.google.com/maps/geo?q="+ placeName+"&output=json"; var response = UrlFetchApp.fetch(url); var str=eval('(' + response.getContentText() + ')').Placemark[ 0].Point.coordinates; return str;} `
Reverse geocoding
Return address by placename
`function getAddress(placeCoord) {// Return Address by placeCoord (reverse geocoding) placeCoord=lat,lng if (placeCoord == "") { return "You have to write the name the place" } var url = "http://maps.google.com/maps/geo?q="+ placeCoord+"&output=json"; var response = UrlFetchApp.fetch(url); var str=eval('(' + response.getContentText() + ')').Placemark[ 0].address; return str;} `
Example