Skip to content

Instantly share code, notes, and snippets.

@jonmarkgo
Created August 21, 2012 20:34
Show Gist options
  • Save jonmarkgo/3419189 to your computer and use it in GitHub Desktop.
Save jonmarkgo/3419189 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Google Maps JavaScript API v3 Example: Heatmap Layer</title>
<link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<script src="https://maps.googleapis.com/maps/api/js?key=XXXX&sensor=false&libraries=visualization"></script>
<script>
// Adding 500 Data Points
var map, pointarray, heatmap;
var taxiData = [
<% checkins.each do | checkin | %>
<% if checkin && checkin.venue && checkin.venue.location %>
new google.maps.LatLng(<%= checkin.venue.location.lat %>, <%= checkin.venue.location.lng %>),
<% end %>
<% end %>
];
function initialize() {
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(37.774546, -122.433523),
mapTypeId: google.maps.MapTypeId.HYBRID
};
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
// pointArray = new google.maps.MVCArray(taxiData);
heatmap = new google.maps.visualization.HeatmapLayer({
data: taxiData
});
heatmap.setMap(map);
changeGradient();
changeRadius();
}
function changeGradient() {
var gradient = [
'rgba(0, 255, 255, 0)',
'rgba(0, 255, 255, 1)',
'rgba(0, 191, 255, 1)',
'rgba(0, 127, 255, 1)',
'rgba(0, 63, 255, 1)',
'rgba(0, 0, 255, 1)',
'rgba(0, 0, 223, 1)',
'rgba(0, 0, 191, 1)',
'rgba(0, 0, 159, 1)',
'rgba(0, 0, 127, 1)',
'rgba(63, 0, 91, 1)',
'rgba(127, 0, 63, 1)',
'rgba(191, 0, 31, 1)',
'rgba(255, 0, 0, 1)'
]
heatmap.setOptions({
gradient: heatmap.get('gradient') ? null : gradient
});
}
function changeRadius() {
heatmap.setOptions({radius: heatmap.get('radius') ? null : 20});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="height: 600px; width: 800px;"></div>
</body>
</html>
require 'sinatra'
require 'foursquare2'
get '/' do
client = Foursquare2::Client.new(:oauth_token => 'abc123')
checkins = []
for i in 0..25
ci = client.user_checkins(:limit => 250, :offset => i*250)
checkins += ci.items
end
puts checkins.to_json
erb :map, :locals => {:checkins => checkins}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment