RSS

Tag Archives: HTML5

How to check HTML5 Web Storage Support in JavaScript?

HTML5 Data Storage

HTML5 Data Storage

function supports_html5_storage() {
                try {
                    return 'sessionStorage' in window && window['sessionStorage'] !== null;
                } catch (e) {
                    return false;
                }
            }
            alert(supports_html5_storage());
Advertisements
 
2 Comments

Posted by on June 26, 2014 in HTML5

 

Tags: ,

HTML5 Geolocation

Demo              Download

<!DOCTYPE html>
<html>
	<head>

		<script src="<a href="view-source:http://maps.googleapis.com/maps/api/js?sensor=false">http://maps.googleapis.com/maps/api/js?sensor=false</a>"></script>
		<script>
			// Integration with google maps
			function loadMap(lat, lng) {
				var latlng = new google.maps.LatLng(lat, lng);

				var settings = {
					zoom: 14,
					center: latlng,
					mapTypeId: google.maps.MapTypeId.ROADMAP
				};

				var map = new google.maps.Map(document.getElementById('map_canvas'), settings);

				var marker = new google.maps.Marker({
					position: latlng,
					map: map,
					title: 'Your Position!'
				});

				document.getElementById('status').innerHTML = 'Position Found!';
			}

			// Initialize geolocation
			function initialize() {
				if (navigator.geolocation) {
					document.getElementById('status').innerHTML = 'Checking...';

					navigator.geolocation.getCurrentPosition(
						onSuccess,
						onError, {
							enableHighAccuracy: true,
							timeout: 20000,
							maximumAge: 120000
						});
				}
				else {
					document.getElementById('status').innerHTML = 'Geolocation not supported.';
				}
			}

			// Map position retrieved successfully
			function onSuccess(position) {
				var data = '';

				data += 'latitude: ' + position.coords.latitude + '<br/>';
				data += 'longitude: ' + position.coords.longitude + '<br/>';
				data += 'altitude: ' + position.coords.altitude + '<br/>';
				data += 'accuracy: ' + position.coords.accuracy + '<br/>';
				data += 'altitudeAccuracy: ' + position.coords.altitudeAccuracy + '<br/>';
				data += 'heading: ' + position.coords.heading + '<br/>';
				data += 'speed: ' + position.coords.speed + '<br/>';

				document.getElementById('data').innerHTML = data;

				loadMap(position.coords.latitude, position.coords.longitude);
			}

			// Error handler
			function onError(err) {
				var message;

				switch (err.code) {
					case 0:
						message = 'Unknown error: ' + err.message;
						break;
					case 1:
						message = 'You denied permission to retrieve a position.';
						break;
					case 2:
						message = 'The browser was unable to determine a position: ' + error.message;
						break;
					case 3:
						message = 'The browser timed out before retrieving the position.';
						break;
				}

				document.getElementById('status').innerHTML = message;
			}
		</script>
	</head>
	<body onload="<a>initialize()</a>">
		<div id="<a>status</a>"></div>
		<div id="<a>data</a>"></div>
		<div id="<a>map_canvas</a>" style="<a>width: 640px; height: 480px</a>"></div>
	</body>
</html>

 
1 Comment

Posted by on April 19, 2012 in Geo Programming, JavaScript

 

Tags: , , ,