geolocate.html 9.44 KB
Newer Older
1
{% load i18n %}
2 3 4 5 6
<!DOCTYPE html>
<html lang="en" style="height: 100%">
  <head>
    <meta charset="utf-8">
    <title>Eduroam</title>
7 8 9 10 11 12
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link REL="shortcut icon" HREF="/static/img/favicon.ico"> 
	<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/img/edu144-icon.png">
	<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/img/edu114-icon.png">
	<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/img/edu72-icon.png">
<link rel="apple-touch-icon-precomposed" href="/static/img/edu-icon.png">
13 14 15 16 17 18
    <meta name="description" content="">
    <meta name="author" content="">

    <script type="text/javascript" src="/static/js/jquery.min.js"></script>
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <script src="/static/js/bootstrap.min.js"></script>
19
    		<script type="text/javascript" src="https://maps.google.com/maps/api/js?v=3.exp&sensor=true&language=en&libraries=places"></script>
20 21 22
    
    <style>
   
23 24 25 26 27
       body {
	padding-top: 40px;
	padding-left: 0px;
    padding-right: 0px;
	/*padding-bottom: 60px;*/
28 29 30 31 32 33 34 35 36 37 38 39
}
#map_canvas {
  /*
  width: 100%;
  height: 100%;
  */
  position: relative;
  height: 100%;
  width: 100%;
  bottom: 0;
  left: 0;
  right: 0;
40
  top: 0px;
41 42 43 44 45 46 47 48 49 50 51 52 53 54
}


.navbar-fixed-top{
margin-bottom: 0px;
}



    </style>
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
	
55 56 57 58
 <link href="/static/css/bootstrap-responsive.min.css" rel="stylesheet">
     <style>
   
       body {
59

60 61 62 63 64 65 66 67 68 69 70 71
	padding-left: 0px;
    padding-right: 0px;
	/*padding-bottom: 60px;*/
}
.container-fluid {
	padding-left: 0px;
	padding-right: 0px;
	}
.pac-container{
	z-index: 3000 !important;
}
</style>
72 73 74 75 76 77 78 79 80 81 82 83
<script type="text/javascript">
	var lat = 36.97;
	var lng = 23.71;
	var zoomLevel = 6;
	var latlng = new google.maps.LatLng(lat, lng);
	var map = '';
	var bounds = '';
	var image = '';
	var marker = '';
	var eduMarker = false;
	var infoWindow;
	var getOnce = false;
84
	var geocoder = null;
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
	var infoWindow;
	var directionDisplay;
    var directionsService = new google.maps.DirectionsService();
	
	var styles = [{
		url : '/static/img/edugroup.png',
		height : 54,
		width : 63,
		textColor : '#ffffff',
		textSize : 11
	}, {
		url : '/static/img/edugroup.png',
		height : 54,
		width : 63,
		textColor : '#ffffff',
		textSize : 11
	}, {
		url : '/static/img/edugroup.png',
		height : 54,
		width : 63,
		textColor : '#ffffff',
		textSize : 11
	}];

	function initialize() {
		
		image = new google.maps.MarkerImage('/static/img/edupin.png',
			new google.maps.Size(29, 40),
			new google.maps.Point(0, 0),
			new google.maps.Point(14, 40)
		);
		var styleArray = [{
			featureType : "all",
			stylers : [{
				saturation : -60
			}, {
				gamma : 1.00
			}]
		}, {
			featureType : "poi.business",
			elementType : "labels",
			stylers : [{
				visibility : "off"
			}]
		}, {
			"featureType" : "transit.line",
			"elementType" : "geometry",
			"stylers" : [{
				"visibility" : "off"
			}]
		}, {
			"featureType" : "poi",
			"elementType" : "all",
			"stylers" : [{
				"visibility" : "off"
			}]
		}, {
			'featureType' : "administrative.country",
			'elementType' : "labels",
			'stylers' : [{
				'visibility' : "off"
			}]
		}];
		var mapOptions = {
			center : latlng,
			zoom : zoomLevel,
			mapTypeId : google.maps.MapTypeId.ROADMAP,
			styles : styleArray,
			mapTypeId : google.maps.MapTypeId.ROADMAP,
			mapTypeControlOptions : {
				style : google.maps.MapTypeControlStyle.DEFAULT
			},
			navigationControl : true,
			mapTypeControl : false,
		};
		map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
161
		
162 163
		var input = document.getElementById('searchTextField');
	    var autocomplete = new google.maps.places.Autocomplete(input);
164

165
	    autocomplete.bindTo('bounds', map);
166
		
167 168 169
		infoWindow = new google.maps.InfoWindow();
		bounds = new google.maps.LatLngBounds();
		directionsDisplay = new google.maps.DirectionsRenderer();
170
		geocoder = new google.maps.Geocoder();
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
		directionsDisplay.setMap(map);
		
		if (getOnce == false) {
				marker = new google.maps.Marker({
					position : latlng,
					draggable : true,
					animation : google.maps.Animation.DROP,

				});
				marker.setMap(map);
			}
		google.maps.event.addListener(map, 'idle', function() {
			if(navigator.geolocation && getOnce == false) {
				navigator.geolocation.getCurrentPosition(getPosition);
			}

		});
		google.maps.event.addListener(map, 'click', function(event) {
			moveMarker(event.latLng);
		});
191
		
192
		google.maps.event.addListener(autocomplete, 'place_changed', function() {
193 194 195 196 197 198 199 200 201
			var place = autocomplete.getPlace();
			console.log(place);
			if (place.geometry.viewport) {
	            map.fitBounds(place.geometry.viewport);
	          } else {
	            map.setCenter(place.geometry.location);
	            map.setZoom(17);  // Why 17? Because it looks good.
	          }
			moveMarker(place.geometry.location);
202
		})
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
	}
	
	function calcRoute(start, end) {
		$("#distanceText").html();
        var request = {
            origin:start,
            destination:end,
            travelMode: google.maps.DirectionsTravelMode.WALKING
        };
        directionsService.route(request, function(response, status) {
          if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
            var route = response.routes[0];
            var distText = route.legs[0].distance.text;
            $("#distanceText").html(distText);
          }
        });
      }

	function moveMarker(position) {
		marker.setPosition(position);
		getClosest(position);
	}

	function getPosition(position) {
		latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
		getOnce = true;
		map.setCenter(latlng);
		map.setZoom(12);
		marker.setPosition(latlng);
		getClosest(latlng);
	}

	function getClosest(coords){
		$.ajax({
			url:"{% url closest %}", 
			data: {"lat": coords.lat(), "lng": coords.lng()},
			type: "GET",
			cache: false,
			success:function(data){
				bounds = new google.maps.LatLngBounds();
				if (eduMarker){
					eduMarker.setMap(null);
				}
				bounds.extend(coords);
				bounds.extend(new google.maps.LatLng(data.lat, data.lng));
				eduMarker = new google.maps.Marker({
					position : new google.maps.LatLng(data.lat, data.lng),
					draggable : true,
					'icon': image,
					animation : google.maps.Animation.DROP,

				});
				eduMarker.setMap(map);
				map.fitBounds(bounds);
				calcRoute(coords, new google.maps.LatLng(data.lat, data.lng));
				google.maps.event
															.addListener(
																	eduMarker,
																	'click',
																	function() {
																		infoWindow.content = "<div>"
																				+ data.text 
																				+ "</div>";
																		infoWindow
																				.open(
																						map,
																						eduMarker);
																	});
			}
		});

	}

277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
function autocomplete() {

        var input = $('#searchTextField');
        var autocomplete = new google.maps.places.Autocomplete(input);

        autocomplete.bindTo('bounds', map);

        var marker = new google.maps.Marker({
          map: map
        });

        google.maps.event.addListener(autocomplete, 'place_changed', function() {
          console.log(autocomplete)
          


        });

        // Sets a listener on a radio button to change the filter type on Places
        // Autocomplete.

      }
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
	
function resizeMap()
{
	h = $(window).height();
	h = h - 55;
	$("div#map_canvas").css({'height' : h+'px' });
	
	
	if (map != undefined)
	{
		google.maps.event.trigger(map, 'resize');
	}
	
	return false;
}
314 315 316

	$(document).ready(function() {
		initialize();
317
		resizeMap();
318
	    $("#localert").delay(6500).fadeOut('slow');
319
		
320
	});
321 322 323 324
	
	$(window).resize(function(){
		resizeMap();
   });
325 326 327 328 329 330

		</script>
  </head>

  <body>

331 332 333 334 335 336 337 338
<div class="navbar navbar-fixed-top" style="margin-bottom: 0px; margin-right: 0px; margin-left: 0px;"">
      <div class="navbar-inner" style="padding: 0px 20px;">
        <div class="container-fluid">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
339
          <a class="brand" href="#" style="font-size: 14px;"><img src="/static/img/eduroam_trans_80pix.png" style="height:20px"> near me</a>
340 341 342
          <ul class="nav">
          <li id="distanceText" style="line-height:40px;" style="font-size: 14px;"></li>
          </ul>
343 344
          <div class="nav-collapse collapse">
            <ul class="nav">
345 346 347
              <li class="hidden-desktop"><span class="alert" style="font-size: 12px;padding: 0 1px;  line-height: 40px;">Accuracy depends on connection type</span></li>
              <li>
				<div class="navbar-search pull-left" style="margin-left: 5px;">q
348
                  <input type="text" class="search-query" placeholder="Search" id="searchTextField">
349
                </div>
350 351
              </li>
              <li class="visible-desktop"><span id="localert" class="alert" style="font-size: 12px;padding: 0 1px;  line-height: 40px;">Accuracy depends on connection type</span></li>
352 353 354 355 356 357
            </ul>
            
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>
358 359 360 361 362 363 364 365 366
<div class="container-fluid">
<div class="row-fluid">
 <div class="span12">
 <div class="row-fluid">
<div id="map_canvas" style="width:100%"></div>
</div>
	</div>
	</div>
	</div>
367 368 369 370

  </body>
</html>