Skip to content

Instantly share code, notes, and snippets.

@rbrancher
Created September 14, 2012 12:36
Show Gist options
  • Save rbrancher/3721673 to your computer and use it in GitHub Desktop.
Save rbrancher/3721673 to your computer and use it in GitHub Desktop.
// SERVER
Meteor.startup(function () {
// code to run on server at startup
Coords = new Meteor.Collection("coords");
Meteor.publish('coords', function () {
return Coords.find();
});
});
// CLIENT
Coords = new Meteor.Collection("coords");
Meteor.subscribe('coords');
Template.coordsList.coords = function () {
return Coords.find();
}
if ("geolocation" in navigator) {
var registerCoords = function (latitude, longitude) {
Coords.insert({latitude: latitude, longitude: longitude});
}
navigator.geolocation.getCurrentPosition(function (position) {
registerCoords(position.coords.latitude, position.coords.longitude);
});
} else {
alert("I'm sorry, but geolocation services are not supported by your browser.");
}
// TEMPLATES
<head>
<title>v&aacute; de moto!</title>
</head>
<body>
<h1>vá de moto!</h1>
{{> coordsList}}
</body>
<template name="coordsList">
<h2>waypoints</h2>
<ul id="coordsList">
{{#each coords}}
<li class="coord"><a href="https://maps.google.com/maps?q={{latitude}},+{{longitude}}&amp;z=16" target="_new">{{latitude}}, {{longitude}}</a></li>
{{/each}}
</ul>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment