Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 70 lines (58 sloc) 1.896 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
</script>

{% for row in rows %}
  <div>
    {% for col in row %}
      <span style="border:1px black solid;margin:3px;">{{col}}</span>
    {% end %}
  </div>
{% end %}

<div id="status"></div>
<article></article>

<script>
function success(position) {
  var s = document.querySelector('#status');
  s.innerHTML = "found you at " +
    position.coords.latitude + ", " +
    position.coords.longitude;
  s.className = 'success';

  var client = new XMLHttpRequest();
  client.open("POST", "/waypoint");
  client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
  client.send(JSON.stringify({
    'position':position,
    'trip_id':{{ trip_id }},
  }));

  var mapcanvas = document.createElement('div');
  mapcanvas.id = 'mapcanvas';
  mapcanvas.style.height = '400px';
  mapcanvas.style.width = '560px';

  document.querySelector('article').appendChild(mapcanvas);

  var latlng = new google.maps.LatLng(position.coords.latitude,
                                      position.coords.longitude);
  var myOptions = {
    zoom: 15,
    center: latlng,
    mapTypeControl: false,
    navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);

  var marker = new google.maps.Marker({
      position: latlng,
      map: map,
      title:"You are here!"
  });
  setTimeout(function() { navigator.geolocation.getCurrentPosition(success, error); },
             1000);
}

function error(msg) {
  var s = document.querySelector('#status');
  s.innerHTML = typeof msg == 'string' ? msg : "failed";
  s.className = 'fail';

  // console.log(arguments);
}

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(success, error);
}

</script>
Something went wrong with that request. Please try again.