Last active
March 9, 2016 07:34
-
-
Save parsley72/9986945 to your computer and use it in GitHub Desktop.
Very basic demo of how to display Keen.io locations on a Google map. I've left out my Project ID and Read Key (for obvious reasons) so to get it to work you need to replace [PROJECT ID], [READ KEY] and [EVENT COLLECTION] with your own settings. Alternatively, go to the Keen.io Workbench for your project, select the Event Collection, set Analysis…
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> | |
<title>Keen.io location map</title> | |
<style> | |
#map-canvas { | |
min-height: 400px; | |
width: 100%; | |
margin: 0px; | |
padding: 0px | |
} | |
</style> | |
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script> | |
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> | |
<script> | |
google.maps.event.addDomListener(window, 'load', function() { | |
var mapOptions = new Object(); | |
mapOptions.zoom = 1; | |
mapOptions.center = new google.maps.LatLng(0, 0); | |
mymap = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); | |
$.getJSON( "https://api.keen.io/3.0/projects/[PROJECT ID]/queries/select_unique?api_key=[READ KEY]&event_collection=[EVENT COLLECTION]&target_property=keen.location.coordinates" , | |
function( data ) { | |
$.each(data.result, function(i, element) { | |
if (element) { | |
var markerPos = new google.maps.LatLng(element[1], element[0]); | |
var marker = new google.maps.Marker({ | |
position: markerPos, | |
map: mymap | |
}); | |
} | |
}); | |
}) | |
.fail(function(jqXHR, textStatus, errorThrown) { alert('getJSON request failed! ' + textStatus); }); | |
}); | |
</script> | |
</head> | |
<body> | |
<div class="panel panel-info"> | |
<div class="panel-heading"> | |
<h3 class="panel-title">Keen.io locations</h3> | |
</div> | |
<div id="map-canvas">Loading ... </div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
{"message": "Your request is missing a required field. Field: 'Queries must contain a time range. The easiest way to do this is with the timeframe parameter. You may also use filters on the keen.timestamp or keen.created_at properties.'.", "error_code": "MissingRequiredRequestFieldError"}
You are missing timeframe parameter
add
&timeframe=this_30_days
wherethis_30_days
isno_of_days
the url should look like this:
https://api.keen.io/3.0/projects/[PROJECT ID]/queries/select_unique?api_key=[READ KEY]&event_collection=[EVENT COLLECTION]&target_property=keen.location.coordinates&timeframe=this_30_days