geolocate.html 10.1 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
}


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

48 49 50
.btnNoBgMove:hover {
    background-position: 0 0;
}
51 52 53 54 55 56

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

62 63 64 65 66 67 68 69 70 71 72 73
	padding-left: 0px;
    padding-right: 0px;
	/*padding-bottom: 60px;*/
}
.container-fluid {
	padding-left: 0px;
	padding-right: 0px;
	}
.pac-container{
	z-index: 3000 !important;
}
</style>
74 75 76 77 78 79 80 81 82 83 84 85
<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;
86
	var geocoder = null;
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 161 162
	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);
163
		
164 165
		var input = document.getElementById('searchTextField');
	    var autocomplete = new google.maps.places.Autocomplete(input);
166

167
	    autocomplete.bindTo('bounds', map);
168
		
169 170 171
		infoWindow = new google.maps.InfoWindow();
		bounds = new google.maps.LatLngBounds();
		directionsDisplay = new google.maps.DirectionsRenderer();
172
		geocoder = new google.maps.Geocoder();
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
		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);
		});
193
		
194
		google.maps.event.addListener(autocomplete, 'place_changed', function() {
195 196 197 198 199 200 201 202
			var place = autocomplete.getPlace();
			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);
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 277
	}
	
	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);
																	});
			}
		});

	}

278 279 280 281 282 283 284 285
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
        });
286
        
287 288

      }
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
	
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;
}
304 305 306

	$(document).ready(function() {
		initialize();
307
		resizeMap();
308 309 310 311 312 313 314 315
		$("#myloc").click(function(){
			navigator.geolocation.getCurrentPosition(getPosition);
			return false;
		});
		$("#mylocm").click(function(){
			navigator.geolocation.getCurrentPosition(getPosition);
			return false;
		});
316
		
317
	});
318 319 320 321
	
	$(window).resize(function(){
		resizeMap();
   });
322 323 324 325 326 327

		</script>
  </head>

  <body>

328 329 330 331 332 333 334 335
<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>
336
          <a class="brand" href="#" style="font-size: 14px;"><img src="/static/img/eduroam_trans_80pix.png" style="height:20px"> near me</a>
337 338 339
          <ul class="nav">
          <li id="distanceText" style="line-height:40px;" style="font-size: 14px;"></li>
          </ul>
340 341
          <div class="nav-collapse collapse">
            <ul class="nav">
342 343
              <li class="hidden-desktop" style="text-align: center"><span class="alert" style="font-size: 12px;padding: 3px 2px;  line-height: 40px;">Accuracy depends on connection type</span></li>
              <li style="text-align: center">
Leonidas Poulopoulos's avatar
Leonidas Poulopoulos committed
344
				<div class="navbar-search pull-left" style="margin-left: 5px;">
345
                  <input type="text" class="search-query" placeholder="Search" id="searchTextField">
346
                </div>
347
              </li>
348 349 350 351 352 353 354
              <li class="hidden-desktop" style="text-align: center;"><button id="mylocm" title="Current location" class="btn btnNoBgMove" style="background: url('/static/img/home_target.png') no-repeat top center; width: 80px; height: 32px; padding: 0px;" href="#"></button></li>
              <li class="visible-desktop"><span id="localert" class="alert" style="font-size: 12px;padding: 3px; 2px;  line-height: 40px;  margin-left: 15px;">Accuracy depends on connection type</span></li>
            </ul>
            <ul class="nav pull-right visible-desktop">
            	<li class="pull-right" style="text-align: center">
            	<button id="myloc" title="Current location" class="btn btnNoBgMove" style="background: url('/static/img/home_target.png') no-repeat top center; width: 32px; height: 32px; padding: 0px;" href="#"></button>
            	</li>
355 356 357 358 359 360
            </ul>
            
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>
361 362 363 364 365 366 367 368 369
<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>
370 371 372 373

  </body>
</html>