Created
March 6, 2013 18:50
-
-
Save saxman/5101960 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The name of the spreadsheet from the browser location bar. | |
// Copy after 'key=' until before the next URL parameter beginning w/& | |
var SPREADSHEET_ID = 'YOUR_SPREADSHEET_ID'; | |
// The name of the sheet, displayed in a tab at the bottom of the spreadsheet. | |
// Default is 'Sheet1' if it's the first sheet. | |
var SHEET_NAME = 'YOUR_SHEET_NAME'; | |
function doGet(request) { | |
var callback = request.parameters.jsonp; | |
var range = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(SHEET_NAME).getDataRange(); | |
var json = callback + '(' + Utilities.jsonStringify(range.getValues()) + ')'; | |
return ContentService.createTextOutput(json).setMimeType(ContentService.MimeType.JSON); | |
} | |
// Testing to see if the jsonp parameter is being used properly. | |
function testDoGet() { | |
var request = {parameters: {jsonp: 'callback'}}; | |
var results = doGet(request); | |
Logger.log(results.getContent()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tokyo | 35676000 | 139.748689741861 | 35.6839177113378 | |
---|---|---|---|---|
New York | 19040000 | -74.0053780488293 | 40.7381845017629 | |
Mexico City | 19028000 | -99.1360208861628 | 19.4343637298345 | |
Mumbai | 18978000 | 72.8293779578763 | 19.0031122972043 | |
Sao Paulo | 18845000 | -46.6488782744749 | -23.5700291320421 | |
Delhi | 15926000 | 77.2092899952401 | 28.6631443881192 | |
Shanghai | 14987000 | 121.403320470608 | 31.2161528692896 | |
Kolkata | 14787000 | 88.3026737620059 | 22.4876238728558 | |
Dhaka | 12797394 | 90.3849270256707 | 23.7123779415253 | |
Buenos Aires | 12795000 | -58.4243794896826 | -34.6100658073734 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>My Awesome Map</title> | |
<style> | |
html, body { | |
margin: 0; | |
padding: 0; | |
width: 100%; | |
height: 100%; | |
} | |
#map_canvas { | |
width: 100%; | |
height: 100%; | |
} | |
</style> | |
<script src="https://maps.google.com/maps/api/js?sensor=false"></script> | |
<script> | |
// The web service URL from Drive 'Deploy as web app' dialog. | |
var DATA_SERVICE_URL = "<YOUR_WEB_SERVICE_URL>?jsonp=callback"; | |
var map; | |
function initialize() { | |
map = new google.maps.Map(document.getElementById('map_canvas'), { | |
center: new google.maps.LatLng(0, 0), | |
zoom: 2, | |
maxZoom: 20, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}); | |
var scriptElement = document.createElement('script'); | |
scriptElement.src = DATA_SERVICE_URL; | |
document.getElementsByTagName('head')[0].appendChild(scriptElement); | |
} | |
function callback(data) { | |
for (var i = 0; i < data.length; i++) { | |
var marker = new google.maps.Marker({ | |
position: new google.maps.LatLng(data[i][3], data[i][2]), | |
map: map | |
}); | |
} | |
} | |
</script> | |
</head> | |
<body onload="initialize()"> | |
<div id="map_canvas"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change MimeType from JSON to JAVASCRIPT