diff options
| author | Daniel Friesel <derf@finalrewind.org> | 2016-05-10 12:21:32 +0200 | 
|---|---|---|
| committer | Daniel Friesel <derf@finalrewind.org> | 2016-05-10 12:21:32 +0200 | 
| commit | 6c37dec8ed54a987acb6665fb6525a39fc6ca5da (patch) | |
| tree | 290e831d119697ff4dd84468e256766c63fd57f2 /public | |
| parent | e09a676a9fac68feca73caffea792c4f0f8eef38 (diff) | |
geolocation playground
Diffstat (limited to 'public')
| -rw-r--r-- | public/static/default.css | 12 | ||||
| -rw-r--r-- | public/static/geolocation.js | 30 | 
2 files changed, 42 insertions, 0 deletions
| diff --git a/public/static/default.css b/public/static/default.css index e18d705..222c9da 100644 --- a/public/static/default.css +++ b/public/static/default.css @@ -404,6 +404,18 @@ div.displaysingle div.info {  	color: #0000ff;  } +div.candidatelist a { +	display: block; +	text-decoration: none; +	color: black; +	padding: 1em; +	margin-top: 0.1em; +	margin-bottom: 0.1em; +	width: 20em; +	text-align: center; +	background-color: #dddddd; +} +  div.about {  	font-family: Sans-Serif;  	color: #666666; diff --git a/public/static/geolocation.js b/public/static/geolocation.js new file mode 100644 index 0000000..78b0691 --- /dev/null +++ b/public/static/geolocation.js @@ -0,0 +1,30 @@ +$(document).ready(function() { +	var processResult = function(data) { +		if (data.error) { +			$('div.candidatelist').text(data.error); +		} else { +			$.each(data.candidates, function(i, candidate) { + +				var ds100 = candidate[0][0], +					name = candidate[0][1], +					distance = candidate[1]; +				distance = distance.toFixed(1); + +				var stationlink = $(document.createElement('a')); +				stationlink.attr('href', ds100); +				stationlink.text(name); +				$('div.candidatelist').append(stationlink); +			}); +		} +	}; + +	var processLocation = function(loc) { +		$.post('/_geolocation', {lon: loc.coords.longitude, lat: loc.coords.latitude}, processResult); +	}; + +	if (navigator.geolocation) { +		navigator.geolocation.getCurrentPosition(processLocation); +	} else { +		$('div.candidatelist').text('Geolocation is not supported by your browser'); +	} +}); | 
